Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
Hi guys,
My goal is to get geometry representation from an active part in PTC Creo Parametric.
I'm parsing User Guide.In section "21 Geometry Evaluation" I found following methods:
• pfcModelItemOwner::ListItems
• pfcSurface::ListContours
• pfcContour::ListElements
At the end of the day, I got the list of edges. The next step in my head is to cast an edge into specific type of the curve it represents: Line, Arc, BSpline.
I wrote following code:
auto line = pfcLine::cast(edge); // << exception appears here
if (line)
{
cout<< "line"<<endl;
}
My problem is this code isn't executed. It throws an exception (First-chance exception at 0x00007FFC9D711F28 in CreoAddIn.exe: Microsoft C++ exception: xthrowable at memory location 0x0000001B916FDF48.)
In the User Guide it's said: "To determine what type of curve a pfcEdge or pfcCurve object represents, use the PTC Creo Object TOOLKIT C++ instanceof operator."
But I couldn't find any kind of such operator anywhere in API(neither in headers nor in API docs). So I decided to cast an edge to every type and check resulting pointer: is it equal to nullptr.
My plan was to cast an edge to corresponding curve type, get control points and\or other useful info from it.
So, can you please provide me with an advice, how to cast an edge in the correct manner?
Thank you in advance,
Artem
Solved! Go to Solution.
Hi Artem -
As I already mentioned in another thread, I don't use OTK C++ very often, but I do use C++ with Creo Parametric Toolkit.
In the User Guide it's said: "To determine what type of curve a pfcEdge or pfcCurve object represents, use the PTC Creo Object TOOLKIT C++ instanceof operator."
But I couldn't find any kind of such operator anywhere in API(neither in headers nor in API docs).
I also noticed only two passing references to instanceof in the User Guide, which also mentions instanceof in the index. I searched the OTK C++ header files with the Unix grep command and did not find a single line containing the word instanceof. I suspect that PTC copied a lot of material between the user guides for OTK C++ and OTK Java, because instanceof is a well-known Java operator.
So, can you please provide me with an advice, how to cast an edge in the correct manner?
Because class pfcEdge inherits from class pfcGeomCurve, you should be able to do something like this:
pfcCurveDescriptor_ptr c_desc = edge.GetCurveDescriptor() ;
pfcCurveType type = c_desc.GetCurveType() ;
if ( type == pfcCURVE_LINE ) {
// This edge is a line
pfcLineDescriptor_ptr l_desc = ( pfcLineDescriptor_ptr ) c_desc ;
}
I haven't tested this code myself, but I hope it helps you.
|+| M a r k |+|
Hi Artem -
As I already mentioned in another thread, I don't use OTK C++ very often, but I do use C++ with Creo Parametric Toolkit.
In the User Guide it's said: "To determine what type of curve a pfcEdge or pfcCurve object represents, use the PTC Creo Object TOOLKIT C++ instanceof operator."
But I couldn't find any kind of such operator anywhere in API(neither in headers nor in API docs).
I also noticed only two passing references to instanceof in the User Guide, which also mentions instanceof in the index. I searched the OTK C++ header files with the Unix grep command and did not find a single line containing the word instanceof. I suspect that PTC copied a lot of material between the user guides for OTK C++ and OTK Java, because instanceof is a well-known Java operator.
So, can you please provide me with an advice, how to cast an edge in the correct manner?
Because class pfcEdge inherits from class pfcGeomCurve, you should be able to do something like this:
pfcCurveDescriptor_ptr c_desc = edge.GetCurveDescriptor() ;
pfcCurveType type = c_desc.GetCurveType() ;
if ( type == pfcCURVE_LINE ) {
// This edge is a line
pfcLineDescriptor_ptr l_desc = ( pfcLineDescriptor_ptr ) c_desc ;
}
I haven't tested this code myself, but I hope it helps you.
|+| M a r k |+|
Hey Mark,
First part about type determination works perfectly fine.
The second part I changed to:
pfcLineDescriptor_ptr l_desc = pfcLineDescriptor::cast(c_desc) ;
Thanks for help, seems I will be able to get necessary info from a part.