part design boolean operation in macro
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
part design boolean operation in macro
is it possible to perform part design boolean operation in a macro?
Re: part design boolean operation in macro
This would be a starting point.
Code below is from PartDesign TestBoolean.py
Code below is from PartDesign TestBoolean.py
Code: Select all
def testBooleanCutCase(self):
self.Body = self.Doc.addObject('PartDesign::Body','Body')
self.Box = self.Doc.addObject('PartDesign::AdditiveBox','Box')
self.Box.Length=10
self.Box.Width=10
self.Box.Height=10
self.Body.addObject(self.Box)
self.Doc.recompute()
self.Body001 = self.Doc.addObject('PartDesign::Body','Body001')
self.Box001 = self.Doc.addObject('PartDesign::AdditiveBox','Box001')
self.Box001.Length=10
self.Box001.Width=10
self.Box001.Height=10
self.Box001.Placement.Base = App.Vector(-5,0,0)
self.Body001.addObject(self.Box001)
self.Doc.recompute()
self.BooleanCut = self.Doc.addObject('PartDesign::Boolean','BooleanCut')
self.Body001.addObject(self.BooleanCut)
self.Doc.recompute()
self.BooleanCut.setObjects([self.Body,])
self.BooleanCut.Type = 1
self.Doc.recompute()
self.assertAlmostEqual(self.BooleanCut.Shape.Volume, 500)
Re: part design boolean operation in macro
Hi
the code returned (PartDesign) by fuse box+cylinder in python console
mario
the code returned (PartDesign) by fuse box+cylinder in python console
Code: Select all
>>> # Gui.Selection.addSelection('Unnamed','Body')
>>> # Gui.Selection.addSelection('Unnamed','Body001')
>>> ### Begin command PartDesign_Boolean
>>> App.getDocument('Unnamed').getObject('Body001').newObject('PartDesign::Boolean','Boolean')
>>> App.getDocument('Unnamed').getObject('Boolean').addObjects([App.getDocument('Unnamed').getObject('Body'),])
>>> App.ActiveDocument.recompute()
>>> App.getDocument('Unnamed').getObject('Boolean').ViewObject.ShapeColor=getattr(App.getDocument('Unnamed').getObject('Cylinder').getLinkedObject(True).ViewObject,'ShapeColor',App.getDocument('Unnamed').getObject('Boolean').ViewObject.ShapeColor)
>>> App.getDocument('Unnamed').getObject('Boolean').ViewObject.LineColor=getattr(App.getDocument('Unnamed').getObject('Cylinder').getLinkedObject(True).ViewObject,'LineColor',App.getDocument('Unnamed').getObject('Boolean').ViewObject.LineColor)
>>> App.getDocument('Unnamed').getObject('Boolean').ViewObject.PointColor=getattr(App.getDocument('Unnamed').getObject('Cylinder').getLinkedObject(True).ViewObject,'PointColor',App.getDocument('Unnamed').getObject('Boolean').ViewObject.PointColor)
>>> App.getDocument('Unnamed').getObject('Boolean').ViewObject.Transparency=getattr(App.getDocument('Unnamed').getObject('Cylinder').getLinkedObject(True).ViewObject,'Transparency',App.getDocument('Unnamed').getObject('Boolean').ViewObject.Transparency)
>>> App.getDocument('Unnamed').getObject('Boolean').ViewObject.DisplayMode=getattr(App.getDocument('Unnamed').getObject('Cylinder').getLinkedObject(True).ViewObject,'DisplayMode',App.getDocument('Unnamed').getObject('Boolean').ViewObject.DisplayMode)
>>> Gui.getDocument('Unnamed').setEdit(App.getDocument('Unnamed').getObject('Body001'), 0, 'Boolean.')
>>> Gui.Selection.clearSelection()
>>> ### End command PartDesign_Boolean
>>> # Gui.Selection.clearSelection()
>>> App.getDocument('Unnamed').getObject('Boolean').setObjects( [App.getDocument('Unnamed').getObject('Body'),])
>>> App.getDocument('Unnamed').getObject('Boolean').Type = 0
>>> App.ActiveDocument.recompute()
>>> Gui.activeDocument().resetEdit()
>>>
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
My macros on Gist.github here complete macros Wiki and forum.
Re: part design boolean operation in macro
thanks for the hints. I think I will have to further look into Part::Boolan class to move forward.
Re: part design boolean operation in macro
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
My macros on Gist.github here complete macros Wiki and forum.
Re: part design boolean operation in macro
super thanks