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.
Solved! Go to Solution.
Solved by ekinsb. Go to Solution.
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(); }