Continue to Site

Welcome to MCAD Central

Join our MCAD Central community forums, the largest resource for MCAD (Mechanical Computer-Aided Design) professionals, including files, forums, jobs, articles, calendar, and more.

help! pro_compute_clearance

coolwind81

New member
Hi,everybody,I am facing a problem about "pro_compute_clearance".


I want to use function "pro_compute_clearance" to check the distancefully programmatically between two component in a assembly without using function"ProSelect().


Here is my code, maybe the assignment "sel[0].part_ptr=NULL;" or "sel[1].part_ptr=NULL;" is not right. the distance I get is always 0.


if(strcmp(name,"TEST_1")==0)


{
sel[0].part_ptr=NULL;
sel[0].assembly_ptr=NULL;
sel[0].memb_num=1;
sel[0].memb_id_tab[0]=40;
sel[0].memb_id_tab[1]=-1;


}
if(strcmp(name,"TEST_2")==0)
{
sel[1].part_ptr=NULL;
sel[1].assembly_ptr=NULL;
sel[1].memb_num=1;
sel[1].memb_id_tab[0]=39;
sel[1].memb_id_tab[1]=-1;
}



status = pro_compute_clearance(sel, PRO_PART_CLEARANCE, &distance,
&interf, coord);


fprintf(fp,"USER Distance is %f\n",distance);
 
You are correct in stating that setting the part_ptr to null is incorrect. You need to have the ProMdl handles to each component you are computing the clearance for. If they are sub assemblies then obviously you will assign the assembly_ptr.
 
To williaps:


thank you very much,


I have tried it again by following you advise, but it's unsuccessful when run to function "pro_compute_clearance",I think the "sel" setting is incorrect. I hope you can help me.


here is my main code:


Select3d *sel;


status = ProMdlCurrentGet ((ProMdl*)&c_asm);
status = ProUtilCollectAsmcomp (c_asm, &asm_comps);
status = ProArraySizeGet ((ProArray)asm_comps, &n_asm_comps);
status = ProArrayAlloc(0, sizeof(Select3d), 2, (ProArray *)&sel);
for (i=0; i<n_asm_comps; i++)
{

status = ProAsmcompMdlNameGet (& (asm_comps), &mdl_type, mdl_name);
ProWstringToString(name,mdl_name);
if(strcmp(name,"TEST_A")==0)
{
ProAsmcompMdlGet(& (asm_comps), &model1);
sel[0].part_ptr=(char *)model1;
sel[0].assembly_ptr=NULL;
sel[0].memb_num=1;
sel[0].memb_id_tab[0]=39;
sel[0].memb_id_tab[1]=-1;


}
if(strcmp(name,"TEST_B")==0)
{
ProAsmcompMdlGet(& (asm_comps), &model2);
sel[1].part_ptr=(char *)model2;
sel[1].assembly_ptr=NULL;
sel[1].memb_num=1;
sel[1].memb_id_tab[0]=43;
sel[1].memb_id_tab[1]=-1;


}
}
status = pro_compute_clearance(sel, PRO_PART_CLEARANCE, &distance, &interf, coord);


fprintf(fp,"USER Distance is %f\n",distance);
 
Well I think I see at least one problem. You are not using the ProArray* functionality properly. You declared a ProSelect3d *sel which is just fine however I would set this to NULL in your declaration. Then you (as you should) allocated memory for the array using ProArrayAlloc. You did not specify the 2 for the correct parameter. You should put the 2 where the 0 is and a 1 where the 2 is. Look up the prototype for ProArrayAlloc. You want to initially allocate 2 of them. Or you could just redeclare sel as ProSelect3d sel[2] and do away with the dynamic allocation. That is the method I would go with.


Another problem that I see is your dereferencing of asm_comps. You are not specifying which element of asm_comps you are using for ProAsmcompMdlGet. asm_comps is an array and you need to reference elements in that array with the bracket [] operator.


The following is how I would write your code above:
Select3d sel[2];
status = ProMdlCurrentGet ((ProMdl*)&c_asm);
status = ProUtilCollectAsmcomp (c_asm, &asm_comps);
status = ProArraySizeGet ((ProArray)asm_comps, &n_asm_comps);
for (i=0; i<n_asm_comps; i++)
{
status = ProAsmcompMdlNameGet (&asm_comps, &mdl_type, mdl_name);
ProWstringToString(name,mdl_name);
if(strcmp(name,"TEST_A")==0)
{
ProAsmcompMdlGet(&asm_comps, &model1);
sel[0].part_ptr=(char *)model1;
sel[0].assembly_ptr=NULL;
sel[0].memb_num=1;
sel[0].memb_id_tab[0]=39;
sel[0].memb_id_tab[1]=-1;
}
if(strcmp(name,"TEST_B")==0)
{
ProAsmcompMdlGet(&asm_comps, &model2);
sel[1].part_ptr=(char *)model2;
sel[1].assembly_ptr=NULL;
sel[1].memb_num=1;
sel[1].memb_id_tab[0]=43;
sel[1].memb_id_tab[1]=-1;
}
}
status = pro_compute_clearance(sel, PRO_PART_CLEARANCE, &distance, &interf, coord);
fprintf(fp,"USER Distance is %f\n",distance);
 
To williaps:


Haha,I have solved it.


Thank you for your kindness.
smiley1.gif
 
Hi,


I have a problem similar to coolwind81's.


I want to use function "pro_compute_clearance" to check the distancefully programmatically between two surfaces without using function"ProSelect().


I use function ProSurfacesCollect to get surfaces instead of using function ProSelect, because I start proe process more than one.


here is my main code


ProSurfacesCollect ( srf_coll_filters,
0,
( ProCollFilter ) NULL,
( ProAppData ) NULL,
collection,
&sel,
&n_sel );

err = ProSrfcollectionRegenerate ( collection,
&regen_sels, &n_regen_sels );


if (err!= PRO_TK_NO_ERROR || n_regen_sels < 2)
{
ProMessageDisplay (msgfil,"USER %0s","..");
}



Select3d *sel_3d;
sel_3d = (Select3d*)&regen_sels;
int status = pro_compute_clearance (sel_3d, PRO_SURFACE_CLEARANCE, &dist,
&interf, coord);







the question is pro_compute_clearance cound not function properly,


when pargram run the last line, it go to ProSurfacesCollect again.


I think I have not set sel_3d value correctly, but how can I modify it?


Please help me
 
You are not calling this function properly. You cannot directly cast a ProSelection to a Select3d structure. Read the section User's Guide->Pro/DEVELOP to Pro/TOOLKIT Function Mapping->Converting from Pro/DEVELOP->Techniques of Conversion and Mixing->Handles and Data Types (Select3d Structure Definition section)for a clear definition of a Select3d structure and how to fill it.
 
To williaps:


I have cast ProSelection to Select3d in new way. But I still havesome questions on it.


I can get the clearance between two surfaces(not plane)which in one part or in diffrent parts. and can get clearance between two plane surfaces in one part.The question is that


I cannot get clearance between two plane surfaces which in diffrent parts- the result dist is always 0 . and the result distance in other case is not correct sometimes also.


Maybe I have cast ProSelection to Select3d in a wrong way?


Can you help me for that?Thank you.





The following is my main code





ProSurfacesCollect ( srf_coll_filters,
0,
( ProCollFilter ) NULL,
( ProAppData ) NULL,
collection,
&sel,
&n_sel );

if (err!= PRO_TK_NO_ERROR ||sel!= 2)
{
ProMessageDisplay (msgfil,"USER %0s","..");
}



Select3d sel_3d[2];
for(int i= 0 ;i< 2;i++)
{
ProAsmcomppathcmp_path;
ProMdlmodel;
ProModelitemmodel_item;
ProUvParamuv_param ;
ProSurfacesurface;



err = ProSelectionAsmcomppathGet(sel,&cmp_path);
err = ProAsmcomppathMdlGet(&cmp_path,&model);
err = ProSelectionModelitemGet(sel,&model_item);
if( model_item.type == PRO_SURFACE)
err = ProSurfaceInit(model_item.owner,model_item.id,&surface);
else
return S_OK;
err = ProSelectionUvParamGet(sel,uv_param);




sel_3d.part_ptr = (char*)model;
sel_3d.assembly_ptr = (char*)(cmp_path.owner);
sel_3d.memb_id_tab[0] = cmp_path.comp_id_table[0];
sel_3d.memb_id_tab[1] = cmp_path.comp_id_table[1];
sel_3d.memb_num = cmp_path.table_num;
sel_3d.selected_ptr = (char*)surface;
sel_3d.sel_param[0] = uv_param[0];
sel_3d.sel_param[1] = uv_param[1];

}
int status = pro_compute_clearance (sel_3d, PRO_SURFACE_CLEARANCE, &dist,
&interf, coord);

Edited by: yang_l_y
 
I noticed that you are not iterating through your sel_3d structure in your loop.


sel_3d.part_ptr = (char*)model;
sel_3d.assembly_ptr = (char*)(cmp_path.owner);
sel_3d.memb_id_tab[0] = cmp_path.comp_id_table[0];
sel_3d.memb_id_tab[1] = cmp_path.comp_id_table[1];
sel_3d.memb_num = cmp_path.table_num;
sel_3d.selected_ptr = (char*)surface;
sel_3d.sel_param[0] = uv_param[0];
sel_3d.sel_param[1] = uv_param[1];



This code should be:


sel_3d.part_ptr = (char*)model;


...


You also need to make sure you are memsetting each element of the Select3d array.
 
about pro_compute_clearance


I found that the wrong result of pro_compute_clearance is not come from interchanging from ProSelection to Select3d
 

Sponsor

Back
Top