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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

How to create Maximum Dimension to all drafting view

KB_9753804
12-Amethyst

How to create Maximum Dimension to all drafting view

Hello everyone ,

 

I have to create maximum dimension to all drafting view , for that I find the maximum and minimum coordinate of solid body using bounding box api , using this coordinates I create datum coordinate system , now I want to add dimension using these coordinate system but it's giving me some error , Please help me to resolve this error ,

I am sharing the code for your reference ,

 

Code : -

void MaxDimension()
{
ProErr err;
ProDrawing drawing;
ProView *views;
Pro3dPnt outline[2];
ProSolid solid;
ProVector csys_pos;
list<ProView> view_collect;

err = ProMdlCurrentGet((ProMdl*)&drawing);
err = ProDrawingViewsCollect(drawing, &views);
int viewCount;
err = ProArraySizeGet((ProArray)views, &viewCount);
for (size_t i = 0; i < viewCount; i++)
{
view_collect.push_front(views[i]);
}
err = ProDrawingViewSolidGet(drawing, view_collect.front(), &solid);
err = ProSolidOutlineGet((ProSolid)solid, outline);
double minCoor[3] = { outline[0][0],outline[0][1],outline[0][2] };
double maxCoor[3] = { outline[1][0], outline[1][1],outline[1][2] };

/*------------------Create Offset Datum Csys To place the dimension ----------------------*/
ProSelection csys_sel;
wchar_t *csys_name = L"PRT_CSYS_DEF";
ProCsys p_csys;
ProModelitem mdlitem;

ProName offset_csys_name_1 = L"PTN01";
ProName offset_csys_name_2 = L"PTN02";

ProUtilCsysFind(solid, csys_name, &p_csys);
err = ProCsysToGeomitem(solid, p_csys, (ProGeomitem*)&mdlitem);
err = ProSelectionAlloc(NULL, &mdlitem, &csys_sel);
err = ProSelectionPoint3dGet(csys_sel, csys_pos);

ProFeature offset_csys_1 = ProDemoGeneralCsysCreate(minCoor[0], minCoor[1], minCoor[2], &csys_sel, offset_csys_name_1, solid);
ProFeature offset_csys_2 = ProDemoGeneralCsysCreate(maxCoor[0], maxCoor[1], maxCoor[2], &csys_sel, offset_csys_name_2, solid);


for (size_t i = 0; i < viewCount; i++)
{
int view_id;
err = ProDrawingViewIdGet(drawing, views[i], &view_id);
err = ProDwgViewRegenerate(drawing, view_id);
}

ProType featureType = PRO_CSYS;
ProModelitem *item1;
ProModelitem *item2;

err = ProUtilCollectFeatureGeomitems(&offset_csys_1, featureType, &item1);
err = ProUtilCollectFeatureGeomitems(&offset_csys_1, featureType, &item2);

ProSelection selection_1;
ProSelection selection_2;

err = ProSelectionAlloc(NULL,item1, &selection_1);
err = ProSelectionAlloc(NULL, item2, &selection_2);

ProGeomitem csys_geom_1;
ProAsmcomppath csys_comppath1;
err = ProSelectionModelitemGet(selection_1, &csys_geom_1);
err = ProSelectionAsmcomppathGet(selection_1, &csys_comppath1);
/*--------------------------------------------------------------------*\
Get the root solid
\*--------------------------------------------------------------------*/
ProSolid newSolid;
if (csys_comppath1.table_num > 0)
newSolid = csys_comppath1.owner;
else
newSolid = (ProSolid)csys_geom_1.owner;

ProSelectionPoint3dGet(csys_sel, csys_pos);

ProMatrix trf1;
ProVector csys_pos1;
if (csys_comppath1.table_num > 0)
{
ProAsmcomppathTrfGet(&csys_comppath1, PRO_B_TRUE, trf1);
ProPntTrfEval(csys_pos, trf1, csys_pos);
}

ProView selView;
ProVector csys_3dpos;
memcpy(csys_3dpos, csys_pos, sizeof(ProVector));
err = ProSelectionViewGet(csys_sel, &selView);
err = ProDrawingViewTransformGet(drawing, selView, PRO_B_TRUE, trf1);
err = ProPntTrfEval(csys_pos1, trf1, csys_pos1);

ProVector view_outline[2];
err = ProDrawingViewOutlineGet(drawing, selView, view_outline);

ProSelection *attachments;
ProDimSense *senses;
ProArrayAlloc(2, sizeof(ProSelection), 1, (ProArray*)&attachments);
ProArrayAlloc(2, sizeof(ProDimSense), 1, (ProArray*)&senses);

senses[0].type = PRO_DIM_SNS_TYP_PNT;
senses[0].sense = PRO_POINT_TYP_CENTER;
senses[0].orient_hint = PRO_DIM_ORNT_VERT;
/*--------------------------------------------------------------------*\
Set up the "sense" information for the csys attachment
\*--------------------------------------------------------------------*/
senses[1].type = PRO_DIM_SNS_TYP_PNT;
senses[1].sense = PRO_POINT_TYP_CENTER;
senses[1].orient_hint = PRO_DIM_ORNT_NONE;

ProSelectionCopy(selection_1, &attachments[0]);
ProSelectionViewSet(selView, &attachments[0]);
ProSelectionCopy(selection_2, &attachments[1]);

ProVector dim_pos;
dim_pos[0] = view_outline[0][0] - 20.0;
dim_pos[1] = (csys_pos1[1]) / 2.0;
dim_pos[2] = 0.0;

ProDimension dimension;
err = ProDrawingDimCreate(drawing, attachments, senses, dim_pos,PRO_B_FALSE, &dimension);
err = ProAnnotationShow((ProAnnotation*)&dimension, NULL, selView);

ProSelectionFree(&attachments[0]);
ProSelectionFree(&attachments[1]);

 

}

1 ACCEPTED SOLUTION

Accepted Solutions
FV
17-Peridot
17-Peridot
(To:KB_9753804)

Most likely you are messing up ProSelection's used in attachments. The portion of code where you are calling ProSelectionAlloc(NULL,...) and after that calling ProSelectionAsmcomppathGet(...) looks somewhat fishy - allocating NULL and calling it back - I don't know...

Unfortunately posted code needs to be refactored. As it is it's quite difficult to follow the overall logic.

The common approach to code structuring is - the top-level function calling workers( helpers). Worker functions should feed data to some global storage struct or pass struct  between themselves as a pointer or a reference if you are using C++ compilation. I'm sure that after the code would be cleaned up it would be much simpler to test and debug each code component instead of dealing with a code blob.

it would also help to manually make coordinate system features , add drawing dimensions, write a function where you would manually select coordinate system features , dimensions, views, etc in the drawing mode and examine resulting ProSelection's in debugger.

HIH.

struct private_data
{
//global variables here
};
static ProError drawing_operations( ProDrawing drawing)
{
//select views and populate private_data with solids
}

static ProError solid_outline_operations( ProSolid solid)
{
// outlines here
// populate private data if needed
}

static ProError solid_coord_systems_make( ProSolid)
{
//make csys here
}
static ProError solid_coord_systems_select(ProSolid)
{
//populate private data with selection objects
}

void MaxDimension()
{
//get current model - must be drawing. pass it to drawing_operations and so on...
//from there get ProSolid's, pass it to csys workers...
//...
}

 

View solution in original post

4 REPLIES 4
FV
17-Peridot
17-Peridot
(To:KB_9753804)

dim_pos1 is not calculated correctly. missing a drawing transformation. as learn-test try to locate the new dimension at the 'middle'.

 

dim_pos[0] = view_outline[0][0] - 20.0;
dim_pos[1] = 0.5*(view_outline[0][1]+view_outline[1][1]);
dim_pos[2] = 0.0;

 

 

for both 'senses' use 

 

p_sense->type = PRO_DIM_SNS_TYP_PNT;
p_sense->sense = PRO_POINT_TYP_NONE;
p_sense->orient_hint = PRO_DIM_ORNT_VERT;

 

PRO_POINT_TYP_NONE should hint to pro/e to pickup whatever is appropriate...

 

HIH.

KB_9753804
12-Amethyst
(To:FV)

Thank you for your help ,  I tried the above changes you suggested  in the code but still it's giving error as PRO_TK_BAD_DIM_ATTACT ,

I am sharing the code for your reference . Please help me to resolve the error

 

Code : - 

void MaxDimension()
{
ProErr err;
ProDrawing drawing;
ProView *views;
Pro3dPnt outline[2];
ProSolid solid;
ProVector csys_pos;
list<ProView> view_collect;

err = ProMdlCurrentGet((ProMdl*)&drawing);
err = ProDrawingViewsCollect(drawing, &views);
int viewCount;
err = ProArraySizeGet((ProArray)views, &viewCount);
for (size_t i = 0; i < viewCount; i++)
{
view_collect.push_front(views[i]);
}
err = ProDrawingViewSolidGet(drawing, view_collect.front(), &solid);
err = ProSolidOutlineGet((ProSolid)solid, outline);
double minCoor[3] = { outline[0][0],outline[0][1],outline[0][2] };
double maxCoor[3] = { outline[1][0], outline[1][1],outline[1][2] };

/*------------------Create Offset Datum Csys To place the dimension ----------------------*/
ProSelection csys_sel;
wchar_t *csys_name = L"PRT_CSYS_DEF";
ProCsys p_csys;
ProModelitem mdlitem;

ProName offset_csys_name_1 = L"PTN01";
ProName offset_csys_name_2 = L"PTN02";

ProUtilCsysFind(solid, csys_name, &p_csys);
err = ProCsysToGeomitem(solid, p_csys, (ProGeomitem*)&mdlitem);
err = ProSelectionAlloc(NULL, &mdlitem, &csys_sel);
err = ProSelectionPoint3dGet(csys_sel, csys_pos);

ProFeature offset_csys_1 = ProDemoGeneralCsysCreate(minCoor[0], minCoor[1], minCoor[2], &csys_sel, offset_csys_name_1, solid);
ProFeature offset_csys_2 = ProDemoGeneralCsysCreate(maxCoor[0], maxCoor[1], maxCoor[2], &csys_sel, offset_csys_name_2, solid);

for (size_t i = 0; i < viewCount; i++)
{
int view_id;
err = ProDrawingViewIdGet(drawing, views[i], &view_id);
err = ProDwgViewRegenerate(drawing, view_id);
}

ProType featureType = PRO_CSYS;
ProModelitem *item1;
ProModelitem *item2;

err = ProUtilCollectFeatureGeomitems(&offset_csys_1, featureType, &item1);
err = ProUtilCollectFeatureGeomitems(&offset_csys_2, featureType, &item2);

ProSelection selection_1;
ProSelection selection_2;

err = ProSelectionAlloc(NULL,item1, &selection_1);
err = ProSelectionAlloc(NULL, item2, &selection_2);

ProGeomitem csys_geom_1;
ProAsmcomppath csys_comppath1;
err = ProSelectionModelitemGet(selection_1, &csys_geom_1);
err = ProSelectionAsmcomppathGet(selection_1, &csys_comppath1);

/*--------------------------------------------------------------------*\
Get the root solid
\*--------------------------------------------------------------------*/
ProSolid newSolid;
if (csys_comppath1.table_num > 0)
newSolid = csys_comppath1.owner;
else
newSolid = (ProSolid)csys_geom_1.owner;
ProSelectionPoint3dGet(csys_sel, csys_pos);

ProMatrix trf1;
ProVector csys_pos1;
if (csys_comppath1.table_num > 0)
{
ProAsmcomppathTrfGet(&csys_comppath1, PRO_B_TRUE, trf1);
ProPntTrfEval(csys_pos, trf1, csys_pos);
}

ProView selView;
ProVector csys_3dpos;
memcpy(csys_3dpos, csys_pos, sizeof(ProVector));
err = ProSelectionViewGet(csys_sel, &selView);
err = ProDrawingViewTransformGet(drawing, selView, PRO_B_TRUE, trf1);
err = ProPntTrfEval(csys_pos1, trf1, csys_pos1);

ProVector view_outline[2];
err = ProDrawingViewOutlineGet(drawing, selView, view_outline);

ProSelection *attachments;
ProDimSense *senses;
ProArrayAlloc(2, sizeof(ProSelection), 1, (ProArray*)&attachments);
ProArrayAlloc(2, sizeof(ProDimSense), 1, (ProArray*)&senses);

senses[0].type = PRO_DIM_SNS_TYP_PNT;
senses[0].sense = PRO_POINT_TYP_CENTER;
senses[0].orient_hint = PRO_DIM_ORNT_VERT;

/*--------------------------------------------------------------------*\
Set up the "sense" information for the csys attachment
\*--------------------------------------------------------------------*/

senses[1].type = PRO_DIM_SNS_TYP_PNT;
senses[1].sense = PRO_POINT_TYP_NONE;
senses[1].orient_hint = PRO_DIM_ORNT_VERT;

ProSelectionCopy(selection_1, &attachments[0]);
ProSelectionViewSet(selView, &attachments[0]);
ProSelectionCopy(selection_2, &attachments[1]);

ProVector dim_pos;
dim_pos[0] = view_outline[0][0] - 20.0;
dim_pos[1] = (view_outline[0][1] + view_outline[1][1]) / 2.0;
dim_pos[2] = 0.0;

ProDimension dimension;
err = ProDrawingDimCreate(drawing, attachments, senses, dim_pos, PRO_B_FALSE, &dimension);
err = ProAnnotationShow((ProAnnotation*)&dimension, NULL, selView);

ProSelectionFree(&attachments[0]);
ProSelectionFree(&attachments[1]);
}

 

 

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

Most likely you are messing up ProSelection's used in attachments. The portion of code where you are calling ProSelectionAlloc(NULL,...) and after that calling ProSelectionAsmcomppathGet(...) looks somewhat fishy - allocating NULL and calling it back - I don't know...

Unfortunately posted code needs to be refactored. As it is it's quite difficult to follow the overall logic.

The common approach to code structuring is - the top-level function calling workers( helpers). Worker functions should feed data to some global storage struct or pass struct  between themselves as a pointer or a reference if you are using C++ compilation. I'm sure that after the code would be cleaned up it would be much simpler to test and debug each code component instead of dealing with a code blob.

it would also help to manually make coordinate system features , add drawing dimensions, write a function where you would manually select coordinate system features , dimensions, views, etc in the drawing mode and examine resulting ProSelection's in debugger.

HIH.

struct private_data
{
//global variables here
};
static ProError drawing_operations( ProDrawing drawing)
{
//select views and populate private_data with solids
}

static ProError solid_outline_operations( ProSolid solid)
{
// outlines here
// populate private data if needed
}

static ProError solid_coord_systems_make( ProSolid)
{
//make csys here
}
static ProError solid_coord_systems_select(ProSolid)
{
//populate private data with selection objects
}

void MaxDimension()
{
//get current model - must be drawing. pass it to drawing_operations and so on...
//from there get ProSolid's, pass it to csys workers...
//...
}

 

KB_9753804
12-Amethyst
(To:FV)

Thank you , Dimension created successfully. 

Top Tags