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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Get the geometry representation from PTC Creo Parametric using object toolkit

abursuk
12-Amethyst

Get the geometry representation from PTC Creo Parametric using object toolkit

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


This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.
ACCEPTED SOLUTION

Accepted Solutions

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  |+|

View solution in original post

2 REPLIES 2

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.

Announcements


Top Tags