During the hackathon we got the following question that Brian answered. I added a picture to make it even easier to understand :)
Q: I’m having a problem extruding a sketch with multiple profiles. I can never seem to create holes. What am I missing?
A: In your case, there are two profiles.
The first consists of the rectangle with the hole (1) and the second is just the hole (2). It’s the same thing you would see in the UI if you draw the sketch and then manually create an extrusion. When you move the mouse within the rectangle, but outside of the circle it will highlight one of the profiles. Moving the mouse into the circle will highlight the other profile. By adding both of them to the collection you were essentially filling the hole. The C++ code below uses some simple logic based on knowledge about the sketch geometry to pick the outer profile (with two ProfileLoop‘s: a and b). This logic will also work if there are multiple holes.
Note: the order of the profiles could be different from the one shown in the picture.
// Put all the profiles in an object collection
// Get the Profiles collection
Ptr<Profiles> pProfiles = sketch->profiles();
Ptr<ObjectCollection> objectsForExtrude = ObjectCollection::create();
for each (Ptr<Profile> pProfile in pProfiles)
{
// Check to see if this is the outer rectangular profile or not
// by checking the number of loops. The outer profile will have two
// loops, one for the rectangle and one for the circle.
Ptr<ProfileLoops> loops = pProfile->profileLoops();
if (loops->count() > 1)
objectsForExtrude->add(pProfile);
}
-Adam


Leave a Reply