Getting the fragments out of BOPTools

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
nmt
Posts: 29
Joined: Sun Feb 19, 2017 2:45 pm

Getting the fragments out of BOPTools

Post by nmt »

Hello,
I am new to FreeCAD and its python scripting. I need to be able to extract the fragments from two intersecting cubes similar to the following example: https://www.freecadweb.org/wiki/Part_BooleanFragments
I was able to write a small python script that gets me the compound object. And if I export a STEP file, I get the correct 3 bodies https://www.dropbox.com/s/yaysd5m5c7115 ... 0.png?dl=0. The problem is that I do not know how to access and display these same three bodies in FreeCAD. Here is the script so far. I would appreciate enhancements to it if it is not quite right (it does run and gives me the expected two cubes):

Code: Select all

doc = FreeCAD.newDocument('TwoBoxes')
Gui.activeDocument().activeView().viewAxonometric()
b1 = doc.addObject("Part::Box","BOX1")
b2 = doc.addObject("Part::Box","BOX2")
b2.Placement.Base.x = 6
b2.Placement.Base.y = 6
b2.Placement.Base.z = 6
b1.ViewObject.Transparency=50
b2.ViewObject.Transparency=50
boxes = [b1, b2]
bf = Part.BOPTools.SplitFeatures.makeBooleanFragments(name= 'BoolFrag')
bf.Objects = boxes
bf.Mode = 'Standard'
bf.ViewObject.Transparency = 60		
doc.recompute()
Gui.SendMsgToActiveView("ViewFit")
So, the question now is: How do I get the three fragments out of bf?

Thanks!
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Getting the fragments out of BOPTools

Post by DeepSOIC »

nmt wrote:So, the question now is: How do I get the three fragments out of bf?

Code: Select all

children = bf.Shape.childShapes()
for child in children:
    Part.show(child)
Draft downgrade might do it as well.
Post Reply