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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Read/write parameters on dimensions

srosell
6-Contributor

Read/write parameters on dimensions

I am using Creo Parametric 4.0 M140

I am trying to read and apply parameters on an annotation, specifically a driven dimension in a 3d model (PRO_DIMENSION or pfcITEM_DIMENSION). When I create a parameter on the modelitem, the parameter gets applied to the .prt that owns the dimension. How do I set a parameter on the actual dimension? What modelitem associated with the dimension owns the parameters? I can access these parameters manually by selecting parameters in the right click menu of the dimension so there must be a way of doing this programmatically.

11 REPLIES 11

HI @srosell,

 

Can you please tell me what are you trying to achieve by associating a parameter to the driving dimension?

 

Do you want the dimension to be controlled using a parameter?

 

Let me know your end requirement. I think i will be able to help you then.

 

Regards,

Deepak

srosell
6-Contributor
(To:dpalakkandy)

I have created a custom Modelcheck that reports on overwritten dimensions. There are a few instances where an overwritten dimension is valid so I want the user to have the ability to ignore a found overwritten dimension so it does not pop up in future Modelchecks. My thought was I would add a parameter to the dimension that would mark it as ignored. The problem I'm running into though is that i cant seem to apply a parameter to the dimension modelitem.

FV
17-Peridot
17-Peridot
(To:srosell)

instead of attaching a parameter to a dimension make a string parameter to hold dimension id's to ignore, make id's comma-delimited. your checks would be as simple as checking for a substring within a main string.

srosell
6-Contributor
(To:FV)

I appreciate the input and I may end up doing something like this in either external data or as a comma delimited model parameter. I still want to figure out why I haven't been able to read/write parameters on dimensions. You can do this manually so there must be a way of doing this programmatically just like any other component or feature parameter.

FV
17-Peridot
17-Peridot
(To:srosell)

check if you have  'TOOLKIT for 3D drawing' license.

the usual approach for param reading is to get an annotation feature, visit  annotation elements, filter out whatever is not PRO_DIMENSION, cast resulting items into ProModelitem and use ProParameterVisit to access ProParameter(s). to write - still need to visit annotation elements, get the one in question , use ProParameterWithUnitsCreate to add a parameter. don't bother with ProParameterInit(...) for anything other than models.

srosell
6-Contributor
(To:FV)

I do have have TOOLKIT for 3D drawings but the way I am trying to do this does not require it. Let me show you what I am doing. 

I have created simple cube part and just added one dimension to the the model using Annotate->Dimension.

Then as a test i run the code below and select the dimension on the prompt. The parameter gets added to the part instead of the dimension. I'm wondering if I'm missing something with getting the annotation element from the dimension object or something like that.

 

void test_dim_param() {
ProError err = PRO_TK_NO_ERROR;
ProSelection* p_sel = NULL;
int n_sel = 0;
ProSelFunctions filter = { NULL, NULL, NULL, NULL };
err = ProSelect("dimension", 1, NULL, &filter, NULL, NULL, &p_sel, &n_sel);
if (err != PRO_TK_NO_ERROR || n_sel == 0) { return; }

ProModelitem dimension_modelitem;
err = ProSelectionModelitemGet(p_sel[0], &dimension_modelitem); // You can see here that the type is PRO_DIMENSION

std::wstring w_test_param_name = L"TEST_PARAM_NAME";
std::wstring w_test_param_value = L"TEST_PARAM_VALUE";

ProParameter param;
ProParamvalue paramvalue;
err = ProParamvalueSet(&paramvalue, w_test_param_value.data(), PRO_PARAM_STRING);
err = ProParameterWithUnitsCreate(&dimension_modelitem, (wchar_t*)w_test_param_name.data(), &paramvalue, NULL, &param);
}

 

FV
17-Peridot
17-Peridot
(To:srosell)

I don't know if 'unfeaturized' driven refdim would work via ProSelect(...). most likely it would not work with visit function. you would need an annotation feature with the dimension for visit function to work.  

maybe something like this:

 

 


static ProError test_dims_collect (ProAnnotationElem* ae, ProError status,
							ProAppData data)
{
  ProArray* p_data = (ProArray*) data;
  ProAnnotationType ae_type = PRO_ANNOT_TYPE_NONE;
   ProError err = ProAnnotationelemTypeGet(ae, &ae_type);
  if(PRO_DIMENSION != ae_type) { return PRO_TK_NO_ERROR;}

  err = ProArrayObjectAdd ((ProArray*)p_data, -1, 1, (void*)ae);
  return PRO_TK_NO_ERROR;
}

void test_dim_param() {
    ProError err = PRO_TK_NO_ERROR;
    ProMdl mdl;

    err = ProMdlCurrentGet( &mdl);
    if (err != PRO_TK_NO_ERROR ) { return; }

    ProModelitem * mi_arr = NULL;
    err = ProArrayAlloc (0, sizeof (ProModelitem),
			  1, (ProArray*) &mi_arr);

    err = ProSolidAnnotationelemsVisit (mdl, 
					 test_dims_collect,
					 NULL,
					 (ProAppData)&mi_arr);

    if (err != PRO_TK_NO_ERROR ) { return; }

    int n = 0;
    err = ProArraySizeGet( (ProArray) mi_arr, &n);
    if (err != PRO_TK_NO_ERROR ) { return; }
    if( n < 1) {return;}

    ProName w_test_param_name = L"TEST_PARAM_NAME";
    ProLine w_test_param_value = L"TEST_PARAM_VALUE";
    ProParamvalue paramvalue;
    err = ProParamvalueSet(&paramvalue, w_test_param_value, PRO_PARAM_STRING);
    if (err != PRO_TK_NO_ERROR ) { return; }

    ProParameter param;
    err = ProParameterWithUnitsCreate(&mi_arr[0], w_test_param_name, &paramvalue, NULL, &param);

    ProArrayFree((ProArray*) &mi_arr);
}

 

 

 

srosell
6-Contributor
(To:FV)

Unfortunately dimension annotations do not seem to be considered annotation elements and do not get visited with ProSolidAnnotationelemsVisit(). I have tested this with both protk and otk. It appears that the dimension only becomes an annotation element once it is consumed by an annotation feature. I wonder if programmatically adding parameters to driven dimensions is something that ptc just doesn't support in Creo 4.

RPN
17-Peridot
17-Peridot
(To:srosell)

If you need only a Boolean information, I would use the dimension symbol and configure it to have a prefix, like iomc_ (ignore on model check),. Doing this would make it easier for a user, and no additional programming to find the match is necessary. Do to the fact of redefine a feature, the dim will even disappear without any additional cleanup for external data or whatever you want to do, to keep that information up to date. Even a relation will be updated on such a rename. 

srosell
6-Contributor
(To:RPN)

I appreciate the suggestion and this may be something to consider if the parameter method isn't possible. I really do want to get to the bottom of why I haven't been able to add parameters to dimensions though.

RPN
17-Peridot
17-Peridot
(To:srosell)

typedef enum param_sel_context 
{
  PRO_PARAMSELECT_ANY                     = -1,
  PRO_PARAMSELECT_MODEL                   = 1<<0,
  PRO_PARAMSELECT_PART                    = 1<<1,
  PRO_PARAMSELECT_ASM                     = 1<<2,
  PRO_PARAMSELECT_FEATURE                 = 1<<3,
  PRO_PARAMSELECT_EDGE                    = 1<<4,
  PRO_PARAMSELECT_SURFACE                 = 1<<5,
  PRO_PARAMSELECT_QUILT                   = 1<<6,
  PRO_PARAMSELECT_CURVE                   = 1<<7,
  PRO_PARAMSELECT_COMPOSITE_CURVE         = 1<<8,
  PRO_PARAMSELECT_INHERITED               = 1<<9,
  PRO_PARAMSELECT_SKELETON                = 1<<10,
  PRO_PARAMSELECT_COMPONENT               = 1<<11,
  PRO_PARAMSELECT_ALLOW_SUBITEM_SELECTION = 1<<12,
  PRO_PARAMSELECT_SENSOR                  = 1<<13  /* for internal use */
} ProParameterSelectContext;

 

This is where you can select, you can't create Parameter for other types. (OFIK)

Announcements


Top Tags