Skip to main content
1-Visitor
June 29, 2018
Solved

ProSelect Error

  • June 29, 2018
  • 2 replies
  • 2656 views

Hi every TK user,

 

I got a big trouble when i used the ProSelcet function to select geometry item.

 

the problem is " when i first time call the fucntion ProSelcet ,the selection object is store in <p_select_1>, but the second time call the fucntion ProSelcet,the selection object not only store in <p_select_2> also store in <p_select_1>."

the first selection object in <p_select_1> was overwrited by second selection object .

do anyone know what's wrong with this problem?

Hope someone can help me,thanks.

 

code:
ProSelection *p_select_1,*p_select_2;
int n_select_1,n_select_2;
err=ProSelect ( "surface,edge", 1, NULL, NULL,NULL, NULL, &p_select_1, &n_select_1);
err=ProSelect ( "surface,edge", 1, NULL, NULL,NULL, NULL, &p_select_2, &n_select_2);

 

 

Best answer by syalagudri

API information says

p_sel_array - A pointer to an array of

<i>ProSelection</i> structures. This

argument points to static memory allocated by the function.

It is reallocated on subsequent calls to this function.

 

Memory will be reallocated. you can convert the Proselection to surface or edge and save it in vector before calling next time Proselect.

Also try once using ProSelectionCopy()

2 replies

14-Alexandrite
June 29, 2018

you have to use ProSelectionAlloc() ?

CAD_Jimmy1-VisitorAuthor
1-Visitor
June 29, 2018

I don't use it.

I think ProSelectionAlloc() is convert <ProModelitem> to <ProSelection>.

But, in here, ProSelect get data type  is <ProSelection> which is i want, so i don't need  ProSelectionAlloc,ringt?

14-Alexandrite
June 29, 2018

API information says

p_sel_array - A pointer to an array of

<i>ProSelection</i> structures. This

argument points to static memory allocated by the function.

It is reallocated on subsequent calls to this function.

 

Memory will be reallocated. you can convert the Proselection to surface or edge and save it in vector before calling next time Proselect.

Also try once using ProSelectionCopy()

21-Topaz I
June 29, 2018

Hi,

 

I do not think that your code:

ProSelection *p_select_1,*p_select_2;
int n_select_1,n_select_2;
err=ProSelect ( "surface,edge", 1, NULL, NULL,NULL, NULL, &p_select_1, &n_select_1);
err=ProSelect ( "surface,edge", 1, NULL, NULL,NULL, NULL, &p_select_2, &n_select_2);

should cause a problem.

OK ,What could be the reason then:

- more trival option but want to mention here is  to check  if your program is compield and linked with the correct options - to verfiy if you compiled the Toolkit program correct  /spawn,dll or asyncronous mode / with the correct setting -  a test could be done if you use some code in the ptc examples and call you code from there.  Example:

...Common Files\protoolkit\x86e_win64\obj\protk_install_example.zip

- what I think the problem what you mention is caused anywere later in your code where you override the one handle by the other...

- for ProSelect you DO not need to allocate memory for the ProSelection handle.

Here an example what I extracted (error handling also removed)   from a working program for UDF creation:

#include <ProSelection.h>
...
int n_sel;
	
ProLine wPrompt;
ProMdl part_mdl;
ProSelection *sels_surface,*sels_surface,SelRefAxis;
ProModelitem pModelitem;
ProUdfdata udf_data;
ProUdfreference reference = NULL;
...
...
status = ProSelect("axis", 1, NULL, NULL , NULL, NULL,&sels_axis, &n_sel);
	
if (status != PRO_TK_NO_ERROR || n_sel != 1)	
return PRO_TK_GENERAL_ERROR;

	
status=ProSelectionCopy (sels_axis[0], &SelRefAxis);

status=ProSelectionModelitemGet (sels_axis[0], &axis_item);
status = ProSelect("surface", 1, NULL, NULL , NULL, NULL,&sels_surface, &n_sel);
	
if (status != PRO_TK_NO_ERROR || n_sel != 1) 	return PRO_TK_GENERAL_ERROR;

	
 	
status=ProSelectionModelitemGet( sels_surface[0], &pModelitem )
;	
status=ProModelitemMdlGet (&pModelitem, &part_mdl);

...
ProStringToWstring(wPrompt , "Platzierungsachse / Placement Axis" );
	
status=ProUdfreferenceAlloc (wPrompt , SelRefAxis /*sels_axis[0]*/ , PRO_B_TRUE , &reference));
status=ProUdfdataReferenceAdd (udf_data, reference);
...

-Roland

CAD_Jimmy1-VisitorAuthor
1-Visitor
June 30, 2018

the problem not caused by later code.

i debug my code. when the code run to second ProSelect() ,the <p_select_1> was override by second selection object immediately.

i think the problem is caused by Syalagudri mention :

p_sel_array - A pointer to an array of

<i>ProSelection</i> structures. This

argument """"points to static memory""""" allocated by the function.

It is reallocated on subsequent calls to this function.

 

so i use ProSelectionCopy() to save ProSelect() seletion object.

thank your reply.