cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

ProSelection Array without user interaction

SOLVED
msteffke
Amethyst

ProSelection Array without user interaction

My program intent tis to create a Shrinkwrap of the current assembly.    

I am using ProSolidShrinkwrapMdlnameCreate to create the SW.  And setting options prior to the function call as shown in the examples.  Export is working, but I need the Shrinkwrap to include a specific Csys.   The csys is a specific name.

 

So to my actual issue -  there are functions to set the options of the Shrinkwrap, and one is for including datum references - perfect!

 ProShrinkwrapoptionsDatumrefsSet  takes for the second argument a ProSelection *   an array of Proselections.  

 

Does anyone have an example where they have generated an array of ProSelection,  using a selection in which they generated from a geomitem?     (there are utilities in the Protk folder to find the csys by name and convert to sel)  I have that.  

 

Thanks for any Help!

1 ACCEPTED SOLUTION

Accepted Solutions

Re: ProSelection Array without user interaction

This is pseudo code not compiled and tested, but should help

 

Spoiler

ProSelection                 selection;

ProModelitem               modelitem;

ProSelection                 *p_sel_arr;

ProMdl                                     model;
iint                                                         id,type;

ProCsys                        csyshandle;

 

 

            // alloc array

            tk_status =  ProArrayAlloc (0, sizeof (ProSelection), 1,        (ProArray*)&p_sel_arr);

 

            // this is a model item as well

            tk_status = ProCsysInit(model,geom_id,&csyshandle);

 

                        or

 

            // by geom id most of the time feat id +1

            tk_status = ProModelitemInit (model, geom_id, PRO_CSYS,&modelitem);

 

                        or

 

            // if a feature was selected

            tk_status = ProModelitemInit (model, feat_id, PRO_FEATURE,&modelitem);

 

 

            // get the valid selection

            tk_status = ProSelectionAlloc(NULL,&modelitem,&selection);

 

 

            // add to array

            tk_status = ProArrayObjectAdd((ProArray*)&p_sel_arr, PRO_VALUE_UNUSED, 1,&selection);

 

View solution in original post

10 REPLIES 10

Re: ProSelection Array without user interaction

extern ProError ProGeomitemToCsys ( ProGeomitem *p_geom_item,
ProCsys *r_csys_handle);
/*
Purpose: Converts a coordinate system <I>ProGeomitem</I> handle to a
<I>ProCsys</I> handle.

Input Arguments:
p_geom_item - The coordinate system geometry item handle

Output Arguments:
r_csys_handle - The coordinate system handle initialized, based on the
input geometry item handle

Return Values:
PRO_TK_NO_ERROR - The function successfully converted the
geometry item handle to a coordinate system handle.
PRO_TK_BAD_INPUTS - The input geometry item handle is invalid, or does not
refer to a coordinate system.
*/

 

with this you can build the model item used in the selection, in an assembly you may need to add the comp path as well.

 

 

Re: ProSelection Array without user interaction

Thanks Aquamarine.  You last statement, "with this you can build the model item used in the selection, in an assembly you may need to add the comp path as well."  This is what I am looking for an example to do this, to create an array of ProSelection.   The csys I am finding is a feature in an assembly.   So does that mean I need to do the component path?

Re: ProSelection Array without user interaction

The selection is allocated with ProSelectionAlloc, here you specify the modelten as an input. If you create a SW from a Part, no comp path, if this (the csys) is at top level in an assy, no comp path. is the csys at member level you need the comp path. 

If you have only one csys, then as far I know the array is also not needed, just the pointer to the selection object. Else you need to deal with ProArray. 

good luck 🍀 

Re: ProSelection Array without user interaction

 The csys is is at top level in the  assy,    im hoping no  comp path.. 
and I only have ovne csys-    I have tried both -    it just wont go.   The functions all return 0 no error, still I get no csys.  

 

Re: ProSelection Array without user interaction

a reasonably close example is : protk_appls\pt_userguide\ptu_mfg\UgMfgMillSeqCreate.c

 

ProSelectionAlloc after ProFeatereGeomItemVisit   - lines 176-185.

ProSelection in ProArray and ProSelectionAlloc - line 314 - 339.

 

HIH.

Re: ProSelection Array without user interaction

God clues I worked hard with this code you pointed out.  I was doing 95% of it so it was goiod confirmation.     Whats getting me is that the definition has p_sel_array as a double pointer.    ProSelection ** p_sel_array.

 I dont understand why it has to be a **.   

 

 

Re: ProSelection Array without user interaction

This is pseudo code not compiled and tested, but should help

 

Spoiler

ProSelection                 selection;

ProModelitem               modelitem;

ProSelection                 *p_sel_arr;

ProMdl                                     model;
iint                                                         id,type;

ProCsys                        csyshandle;

 

 

            // alloc array

            tk_status =  ProArrayAlloc (0, sizeof (ProSelection), 1,        (ProArray*)&p_sel_arr);

 

            // this is a model item as well

            tk_status = ProCsysInit(model,geom_id,&csyshandle);

 

                        or

 

            // by geom id most of the time feat id +1

            tk_status = ProModelitemInit (model, geom_id, PRO_CSYS,&modelitem);

 

                        or

 

            // if a feature was selected

            tk_status = ProModelitemInit (model, feat_id, PRO_FEATURE,&modelitem);

 

 

            // get the valid selection

            tk_status = ProSelectionAlloc(NULL,&modelitem,&selection);

 

 

            // add to array

            tk_status = ProArrayObjectAdd((ProArray*)&p_sel_arr, PRO_VALUE_UNUSED, 1,&selection);

 

View solution in original post

Re: ProSelection Array without user interaction

Oh man - you made my day.   My Coord system is finally appearing!!

 

I think it was the  (ProArray*)&p_sel_arr,   portion of the line,  The rest I was already doing verbatim.   Basically lost in pointer land.  

 

tk_status = ProArrayObjectAdd((ProArray*)&p_sel_arr, PRO_VALUE_UNUSED, 1,&selection);

 

I thank you for your suggestion and also everyone else who has responded in this post, I was stuck for several days with NO progress.  

 

Re: ProSelection Array without user interaction


@msteffke wrote:

God clues I worked hard with this code you pointed out.  I was doing 95% of it so it was goiod confirmation.     Whats getting me is that the definition has p_sel_array as a double pointer.    ProSelection ** p_sel_array.

 I dont understand why it has to be a **.   

 

 


The reason for **p_sel_array is that ProArray is in essence a contiguous area of heap allocated memory holding some/any data. This memory has to be reserved somehow and this is where  ProArrayAlloc is coming to play. As usual C language 'pass-a-pointer-by-value' approach - the last argument of ProArrayAlloc has to be a pointer to something - therefore '(void*) last_arg'. Now, what is hidden by (void*) construct - the answer is a pointer to an array of ProSelection things. What is an array of ProSelection ( or char for that matter) ? The answer is 

ProSelection *pro_sel_arr;

 combine that with (void*) from ProArrayAlloc and you would get 'void* ProSelection*' which is (ProSelection**).  'pro_sel_arr' variable has to be pointed-to in order to match (ProSelection**) and will become '&pro_sel_arr' in the function call: ProArrayAlloc( ...., (ProSelection**) &pro_sel_arr) or it could be rewritten step by step:

ProSelection* pro_sel_arr = NULL; // will hold an address of heap memory in the future...
ProSelection** pointer_to_pro_sel_arr_variable = &pro_sel_arr; //address of pro_sel_arr variable
ProArrayAlloc( ...., (ProSelection**) pointer_to_pro_sel_arr_variable);
//the same as calling
ProArrayAlloc( ..., (ProSelection**) &pro_sel_arr);

 

Re: ProSelection Array without user interaction

Thanks for this explanation-  this is helpful!

Announcements