Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

pulling faces from a body from a component

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
charliex2
270 Views, 2 Replies

pulling faces from a body from a component

My code is working when i select a face and then use  PTR<BRepFace> face = selection->entity() but when i try to scan through the list of components and then bodies, body , faces and then face, i always seem to end up with a face that belongs to a body elsewhere. 

 

 

 

app = Application::get();

Ptr<Product> product = app->activeProduct();

Ptr<Design> design = product;

Ptr<Component> rootComp = design->rootComponent();

Ptr<OccurrenceList> occurenceList = rootComp->allOccurrences();

size_t occurenceCount = occurenceList->count();

 

   Ptr<Component> component ;

   for loop i 0 to occurrenceCount {

 

       component  =  occurrenceList->item ( i )->component();

 

       // match the component name from component->name()

 

       //if matches

       Ptr<BRepBodies> bodies = component->bRepBodies();

 

       // find body by name

       Ptr<BRepBody> body = bodies->itemByName ( "Body2" );

 

       Ptr<BRepFaces> faces = body->faces();

       Ptr<BRepFace> face = faces->item ( 0 );

 

      // always returns same points regardless of which component, it finds the right name, right face count (6) but always same point which isn't part of the component body.

 

       Ptr<Point3D> pnt3DCentroid = face->centroid();

 }

 

i'm sure its something simple.

2 REPLIES 2
Message 2 of 3
ekinsb
in reply to: charliex2

It all has to do with "context".  The real body exists within a component, which has it's own local coordinate system.  What you actually see in the UI, with the exception of the root component, is a reflection of that component through an occurrence or instance of that component.  Occurrences can be positioned anywhere within the assembly and are positioned with respect to the world coordinate system (the local coordinate system of the root component).  In your code, you're getting the component that is referenced by an occurrence.  At this point you're now working on the local coordinate system of the component so any geometry queries will be in the context of that local coordinate system.  Here's a modified version of your program that doesn't go to the component but gets the body from the occurrence.  We refer to this as a body "proxy" because it's the not real body a body acting in place of the real body and takes into account the position of the occurrence.  You can read a bit more about this in this help topic.

 

 

app = Application::get();
Ptr<Product> product = app->activeProduct();
Ptr<Design> design = product;
Ptr<Component> rootComp = design->rootComponent();
Ptr<OccurrenceList> occurenceList = rootComp->allOccurrences();
size_t occurenceCount = occurenceList->count();
 
   Ptr<Component> component ;
   for loop i 0 to occurrenceCount {
       // match the component name from component->name()
 
       //if matches
       Ptr<BRepBodies> bodies = occurrenceList->item(i)->bRepBodies();
 
       // find body by name
       Ptr<BRepBody> body = bodies->itemByName( "Body2" );
 
       Ptr<BRepFaces> faces = body->faces();
       Ptr<BRepFace> face = faces->item ( 0 );
 
      // always returns same points regardless of which component, it finds the right name, right face count (6) but always same point which isn't part of the component body.
       Ptr<Point3D> pnt3DCentroid = face->centroid();
 }

 

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 3
charliex2
in reply to: ekinsb

ok makes sense, so i was grabbing LCS vs WCS, thanks! figured it was something simple

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report