Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X
How to get the reference edges for a selected dimension using ProToolKit Creo3.0?
So I think to get the edges of a dimension here means that you want to get the geometrical references of the dimensions.
- so for example when you select an dimension you can get via ProSelectionModelitemGet the model item and when it is a PRO_DIMENSION then you can use the API ProDimensionAttachmentsGet() to get the references. So it could be some code like this below:
/*==================================================================*\
FUNCTION : TestAnnotDimAttachmentWrite()
PURPOSE : Writes Dimensions Attachment to a file.
\*==================================================================*/
ProError TestAnnotDimAttachmentWrite (ProDimension* dimension)
{
char var [PRO_FILE_NAME_SIZE];
char line [500];
ProError status1;
ProAnnotationPlane ap_get;
ProDimAttachment *pro_array_dim_attachment_get;
ProDimSense *pro_array_dim_sense_get;
ProDimOrient orient_hint_get;
ProDimensiontype dim_type_get;
int i,j,k;
ProModelitem p_mdl_item;
int dim_sense_array_size,dim_sense_array_size_low,counter,counter_low,dim_attach_array_size;
int arr_size;
status = ProDimensionTypeGet (dimension,&dim_type_get);
MY_ERR_CHECK("ProDimensionTypeGet()", status, status != PRO_TK_NO_ERROR);
status = ProDimensionAttachmentsGet (dimension,
&ap_get,
&pro_array_dim_attachment_get,
&senses_arr,
&orient_hint_get);
MY_ERR_CHECK("ProDimensionAttachmentsGet()", status, status != PRO_TK_NO_ERROR);
if(status == PRO_TK_NO_ERROR)
{
/*------------------------------------------------------------------------
Info of ProDimAttachment : DIMENSION ATTACHMENTS .
-----------------------------------------------------------------------*/
if(pro_array_dim_attachment_get != NULL)
{
status = ProArraySizeGet ((ProArray*)pro_array_dim_attachment_get ,
&dim_attach_array_size);
MY_ERR_CHECK_SUCC("ProArraySizeGet()");
if(status == PRO_TK_NO_ERROR)
{
sprintf (line,
" + Dimension Attachments (%d found):",
dim_attach_array_size);
printf (line);
/* Traverse through 'dim_attach_array_size' number of 'ProDimAttachment' objects */
for(i = 0 ; i < dim_attach_array_size ; i++)
{
/* Each 'ProDimAttachment' contains 2 ProSelection Handles
Traversing through these handles and writing their info */
for(j = 0 ; j < 2 ; j++)
{
sprintf (line, " - Dimension attachment [%d][%d]",
i+1, j+1);
my_line_printf (line);
if(pro_array_dim_attachment_get[i][j] != NULL)
{
do_something_with_particular_attachment (pro_array_dim_attachment_get[i][j]);
}
else
{
my_line_printf(" > NULL \n");
}
}
}
}/* if(status == PRO_TK_NO_ERROR)*/
ProDimattachmentarrayFree (pro_array_dim_attachment_get);
} /* if(pro_array_dim_attachment_get != NULL) */
}/* if(status1 == PRO_TK_NO_ERROR) */
return PRO_TK_NO_ERROR;
}
...
ProError testModelDims(ProMdl mdl,ProDrawing drw,ProView view,ProAsmcomppath *comp_path)
{
DimAppData app_data;
app_data.drw=drw;
app_data.view=view;
app_data.p_comp_path=comp_path;
Log("==> Fired testModelDims here ");
//refdim true, standard dims false
ERR( ProSolidDimensionVisit( (ProSolid) mdl , PRO_B_FALSE, UserDimensionAction, UserDimensionFilter ,(ProAppData*) &app_data));
return PRO_TK_NO_ERROR;}
/*************************************************************************/
ProError UserDimensionFilter (ProDimension* dim, ProAppData appdata)
{
ProError err;
DimAppData *app_data=(DimAppData*) appdata;
ProBoolean is_shown=PRO_B_FALSE;
ERR_INFO(ProAnnotationIsShown((ProAnnotation*) dim,(ProDrawing) app_data->drw,&is_shown))
if(is_shown)
{
Log( "\n UserDimensionFilter dim_id=%d is SHOWN", dim->id);
//return (PRO_TK_NO_ERROR);//we do know need already shown dimensions
return(PRO_TK_E_FOUND);
}
else
{ Log( "\n UserDimensionFilter dim_id=%d is INVISIBLE", dim->id);
//return(PRO_TK_CONTINUE); // will not filter here for shown
return (PRO_TK_E_NOT_FOUND);
}
}
/*************************************************************************/
ProError UserDimensionAction (ProDimension* dim, ProError error_status, ProAppData appdata)
{
ProError err;
double value;
ProDimlocation dimloc;
ProPoint3d arr1, arr2,witn1,witn2;
ProView view;
ProName wname,wname1;
char name[256];
char name1[256];
ProSelection sel;
DimAppData *app_data=(DimAppData*) appdata;
ERR( ProDimensionValueGet(dim, &value));
if(error_status==PRO_TK_E_FOUND)
{
ERR(ProDrawingDimensionViewGet((ProDrawing) app_data->drw, dim, &view))
ERR(ProDrawingViewNameGet((ProDrawing) app_data->drw,view,wname))
ProWstringToString(name,wname);
ERR(ProDrawingViewNameGet((ProDrawing) app_data->drw,app_data->view,wname1))
ProWstringToString(name1,wname1);
Log( "DIMENSION[ID=%i], Value=%f",dim->id, value);
if(strcmp(name, name1) != 0) //not the same
{
Log("Visit_VIEW[%s] and DIM_VIEW[%s] \nare different BREAKs the method...",name1,name);
return (PRO_TK_NO_ERROR);
}
else
{
Log("Visit_VIEW[%s] and DIM_VIEW[%s] \n are the same CONTINUEs the method...",name1,name);
return (PRO_TK_NO_ERROR);
}
/*ERR( ProDimensionLocationGet(dim, view, (ProDrawing) appdata, &dimloc)) */
ERR(ProSelectionAlloc(NULL,(ProModelitem *) dim, &sel))
ERR(ProSelectionViewSet(view,&sel))
err = ProDimensionLocationGet(dim, NULL, (ProDrawing) app_data->drw, &dimloc);
if (!err) ProSelectionHighlight(sel,PRO_COLOR_SHEETMETAL);
else ProSelectionHighlight(sel,PRO_COLOR_ERROR);
if (!err) {
ERR( ProDimlocationArrowsGet(dimloc, arr1, arr2))
Log("\nArrow1=(%f,%f,%f), Arrow2=(%f,%f,%f)\n",
arr1[0], arr1[1], arr1[2], arr2[0], arr2[1], arr2[2]);
ERR(ProDimlocationWitnesslinesGet(dimloc, witn1, witn2))
Log("\nWitness1=(%f,%f,%f), Witness2=(%f,%f,%f)\n",
witn1[0], witn1[1], witn1[2], witn2[0], witn2[1], witn2[2]);
ERR( ProDimlocationFree(dimloc))
}
else {
Log( "ERROR = %d\n",err);
}
}
if(error_status==PRO_TK_E_NOT_FOUND)
{
Log("TRY TO SHOW this DIM");
ERR_INFO(ProAnnotationDisplay((ProAnnotation* ) dim,(ProAsmcomppath*) app_data->p_comp_path,app_data->drw,app_data->view))
if(err_ray == PRO_TK_NO_ERROR)
//shows permanent
ERR_INFO(ProAnnotationShow((ProAnnotation* ) dim,app_data->p_comp_path,app_data->view))
}
return (PRO_TK_NO_ERROR);
}
/*************************************************************************/
...
Hi,
Thanks for the quick response.
I actually want to get edges of selected dimension which i have highlighted in the attached image. Is there any way to achieve this?
OK this means case 1.) (the first sample code)
do_something_with_particular_attachment (pro_array_dim_attachment_get[i][j]);
where the input argument of this function should be a selection with the geometrical references - it coud be an edge or vertex on boundary ...etc (did not check what will be accepted as valid references for the annotation element ... I am not sure if it will accept a flat surface or plane)
you can for example highlight it with
ProSelectionHighlight(pro_array_dim_attachment_get[i][j], PRO_COLOR_SELECTED);
here in the example for the pro_array_dim_attachment_get[i][j] - means i - the number of the model dimension
and j could be [0;1] one of the possible 2 refences for i-th dimension.
