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 set leader attachment position to surface

KB_9753804
12-Amethyst

How to set leader attachment position to surface

Hello everyone,

 

I create leader note , for that I passed surface selection with view and pointed , but still It goes outside the view , please help me to resolve the issue.

I shared the code for your reference.

 

ProError ProTestDrawingNoteWithLeader(ProDrawing drawing,ProSolid solid, ProCharLine str, ProCharLine str1, ProView isoView, ProSurface surf, ProVector noteLocation)
{
ProError status;
ProDtlnotedata ndata;
ProDtlnoteline line;
ProDtlnoteline line1;
ProLine wstr;
ProLine wstr1;
ProDtlnotetext text;
ProDtlnotetext text1;
double height = 6;
ProDtlnote note;
ProDtlattach attach, leader;
ProBoolean isShown;

ProStringToWstring(wstr, str);
ProStringToWstring(wstr1, str1);

status = ProDtlnotedataAlloc(drawing, &ndata);
status = ProDtlnotetextAlloc(&text);
status = ProDtlnotetextHeightSet(text, height);
status = ProDtlnotetextWidthSet(text, 0.8);
status = ProDtlnotetextSlantSet(text, 0.0);
status = ProDtlnotetextThicknessSet(text, 0.0);

status = ProDtlnotetextAlloc(&text1);
status = ProDtlnotetextHeightSet(text1, height);
status = ProDtlnotetextWidthSet(text1, 0.8);
status = ProDtlnotetextSlantSet(text1, 0.0);
status = ProDtlnotetextThicknessSet(text1, 0.0);

status = ProDtlnotetextStringSet(text, wstr);
status = ProDtlnotetextStringSet(text1, wstr1);
status = ProDtlnotelineAlloc(&line);
status = ProDtlnotelineAlloc(&line1);
status = ProDtlnotelineTextAdd(line, text);
status = ProDtlnotelineTextAdd(line1, text1);
status = ProDtlnotedataLineAdd(ndata, line);
status = ProDtlnotedataLineAdd(ndata, line1);

ProModelitem modelItem;
status = ProSurfaceToGeomitem(solid, surf, (ProGeomitem*)&modelItem);

ProSelection surfSel;
status = ProSelectionAlloc(NULL, (ProModelitem*)&modelItem, &surfSel);

ProSelection p_sel;
status = ProSelectionAlloc(NULL, (ProModelitem*)&modelItem, &p_sel); //ProArrayAlloc(1, sizeof(ProSelection), 1, (ProArray*)&p_sel);
status = ProSelectionViewSet(isoView,&p_sel);

ProGeomitemdata *srfData;
status = ProSurfaceDataGet(surf, &srfData);

ProContour *surface_counter;
ProEdge *edges;

status = ProUtilCollectSurfaceContours(surf, &surface_counter);
status = ProUtilCollectContourEdges(surf, surface_counter[0], &edges);

ProVector start_point;
ProVector end_Point;
ProEnttype type;
ProVector deriv1;
ProVector deriv2;
ProVector direction;

status = ProEdgeXyzdataEval(edges[0], 0.0, start_point, deriv1, deriv2, direction);
status = ProSelectionPoint3dSet(start_point, &p_sel);

status = ProDtlattachAlloc(PRO_DTLATTACHTYPE_FREE, isoView, noteLocation, NULL, &attach);
status = ProDtlnotedataAttachmentSet(ndata, attach);

status = ProDtlattachAlloc(PRO_DTLATTACHTYPE_PARAMETRIC, NULL, NULL,p_sel, &leader);
status = ProDtlnotedataLeaderAdd(ndata, leader);

status = ProDtlnoteCreate(drawing, NULL, ndata, &note);
status = ProDtlnotedataDisplayedSet(ndata, PRO_B_TRUE);
status = ProDrawingViewRegenerate(drawing, isoView);
status = ProAnnotationIsShown((ProAnnotation*)&note, drawing, &isShown);

if (isShown == PRO_B_FALSE)
{
status = ProAnnotationShow((ProAnnotation*)&note, NULL, isoView);
}
status = ProDtlnotedataFree(ndata);
status = ProDtlnotetextFree(text);
status = ProDtlattachFree(attach);
status = ProDtlattachFree(leader);
return (status);
}

 

1 ACCEPTED SOLUTION

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

Most likely the same problem as in:

Solved: Creo ProToolkit API pfcSelection::SetPoint() is no... - PTC Community

 

when working with surfaces or edges there should be ProSelectionUvParametSet() call.

View solution in original post

5 REPLIES 5
RPN
17-Peridot
17-Peridot
(To:KB_9753804)

I’m not at my desk, but I guess you need to transform your point to screen coordinates. This implements a user action in a drawing, where the user picks the location in the drawing. This is not the same.

KB_9753804
12-Amethyst
(To:RPN)

Dear sir, 

I transform the point to screen coordinate but still it goes outside the boundary ,I share the code for your reference.

 

ProError ProTestDrawingNoteWithLeader(ProDrawing drawing, ProCharLine str, ProCharLine str1, ProView isoView, ProSurface surf, ProVector noteLocation)
{
ProError status;
ProDtlnotedata ndata;
ProDtlnoteline line;
ProDtlnoteline line1;
ProSolid solid;
ProMatrix trf;

ProLine wstr;
ProLine wstr1;
ProDtlnotetext text;
ProDtlnotetext text1;

double height = 0.1;
ProDtlnote note;
ProDtlattach attach, leader;
ProBoolean isShown;

ProStringToWstring(wstr, str);

ProStringToWstring(wstr1, str1);

status = ProDrawingViewSolidGet(drawing, isoView, &solid);

status = ProDrawingViewTransformGet(drawing, isoView, PRO_B_TRUE, trf);

status = ProDtlnotedataAlloc(drawing, &ndata);

status = ProDtlnotetextAlloc(&text);

status = ProDtlnotetextAlloc(&text1);

status = ProDtlnotetextStringSet(text, wstr);

status = ProDtlnotetextStringSet(text1, wstr1);

status = ProDtlnotelineAlloc(&line);

status = ProDtlnotelineAlloc(&line1);

status = ProDtlnotelineTextAdd(line, text);

status = ProDtlnotelineTextAdd(line1, text1);

status = ProDtlnotedataLineAdd(ndata, line);

status = ProDtlnotedataLineAdd(ndata, line1);

ProModelitem reqSurfaceItem;
ProContour *p_contour;
ProEdge* p_edges;
int p_contour_count;
ProSelection *attatchment;
ProVector start_point;
ProEnttype type;
ProVector deriv1;
ProVector deriv2;
ProVector direction;
ProVector out_Point;
ProSelection surfSel;

status = ProSurfaceToGeomitem(solid, surf, (ProGeomitem*)&reqSurfaceItem);

status = ProUtilCollectSurfaceContours(surf, &p_contour);

status = ProUtilCollectContourEdges(surf, p_contour[0], &p_edges);

status = ProEdgeXyzdataEval(p_edges[0], 1.0, start_point, deriv1, deriv2, direction);

//=================== Evalue Point on Surface ============================//
ProPoint3d p1 = { start_point[0],start_point[1],start_point[2] };

ProPoint3d closed_Point;

ProBoolean on_Surf;

status = ProPoint3dOnsurfaceFind(p1, surf, &on_Surf, closed_Point);

if (on_Surf == PRO_B_TRUE)
{
status = ProPntTrfEval(start_point, trf, out_Point);
}
else
{
status = ProPntTrfEval(closed_Point, trf, out_Point);
}

status = ProSelectionAlloc(NULL,(ProModelitem*)&reqSurfaceItem, &surfSel);

status = ProArrayAlloc(1, sizeof(ProSelection), 1, (ProArray*)&attatchment);

status = ProSelectionCopy(surfSel, &attatchment[0]);

status = ProSelectionPoint3dSet(out_Point, &attatchment[0]);

status = ProSelectionViewSet(isoView, &attatchment[0]);

status = ProDtlattachAlloc(PRO_DTLATTACHTYPE_FREE, isoView, noteLocation, NULL, &attach);

status = ProDtlnotedataAttachmentSet(ndata, attach);

status = ProDtlattachAlloc(PRO_DTLATTACHTYPE_PARAMETRIC, NULL, NULL, attatchment[0], &leader);

status = ProDtlnotedataLeaderAdd(ndata, leader);

status = ProDtlnoteCreate(drawing, NULL, ndata, &note);

status = ProDtlnotedataDisplayedSet(ndata, PRO_B_TRUE);

status = ProDrawingViewRegenerate(drawing, isoView);

status = ProAnnotationIsShown((ProAnnotation*)&note, drawing, &isShown);

if (isShown == PRO_B_FALSE)
{
status = ProAnnotationShow((ProAnnotation*)&note, NULL, isoView);
}

status = ProDtlnotedataFree(ndata);

status = ProDtlnotetextFree(text);

status = ProDtlattachFree(attach);

status = ProDtlattachFree(leader);

return (status);
}

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

You have two options:

  1. Create in Creo a point and extract the placement xy points
  2. Create with Toolkit a point 

For both check the difference, I guess it's a transformation issue.

 

ProDrawingViewTransformGet (

...

ProBoolean view_to_drawing

..)

For me this should be TRUE (You have true) because you want the transform from the Model View to Drawing Coords.

Did you validate the given Drawing View?

If you use 1.0 hard coded for the edge, are you sure this is valid and possible (I knew 0.0 - 1.0, but ...) ?

Same here first figure out how to create just a point within the drawing at the requested position. You can measure this in your model and use this in your code for testing. 

 

 

Is noteLocation correct?

 

ProDtlattachAlloc(

...

location - The attachment location. Use if
the attachment type is set to PRO_DTLATTACHTYPE_FREE
or PRO_DTLATTACHTYPE_OFFSET.
For drawing objects and symbols and surface finish on
flat-to-screen annotation planes, this should be in
screen coordinates. For symbols and surface finish on
3D model annotation planes, this should be in model
coordinates.

...)

 

 

 

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

Most likely the same problem as in:

Solved: Creo ProToolkit API pfcSelection::SetPoint() is no... - PTC Community

 

when working with surfaces or edges there should be ProSelectionUvParametSet() call.

KB_9753804
12-Amethyst
(To:FV)

Thank you , after setting the UV parameter , Leader positioned at correct location

Top Tags