Python function for Union
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Python function for Union
What is the python function for Part -> Union? I managed to union/fuse two shells in GUI but cannot find corresponding python function?
Re: Python function for Union
The function is Fusion. Most commands are logged in Python console, so it's always worth a try to do something from the GUI while watching the console.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Re: Python function for Union
But Python complains that
module 'Part' has no attribute 'Fusion'
It also complains if I try MultiFuse instead of Fusion
module 'Part' has no attribute 'Fusion'
It also complains if I try MultiFuse instead of Fusion
Re: Python function for Union
Sorry for being short/wrong. Let's assume you have a Box and a Cylinder in your document. Then you can do the following:
Code: Select all
doc = App.ActiveDocument
doc.addObject("Part::MultiFuse","Fusion")
doc.Fusion.Shapes = [doc.Box,doc.Cylinder]
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Re: Python function for Union
Keep the Python console open. Then perform the actions that you want in the graphical interface, that is, grab two objects, and press Part_Union. You will see the commands that produce that object recorded in the Python console. Now you can take that code and adapt it to your needs. This is what chrisb did. It's the same process that is done when you record macros.
It's the best way to learn Python scripting with FreeCAD. Just perform operations with the buttons, see the generated code, and then repeat those same steps.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: Python function for Union
in python, it's more commonly needed to operate on shapes, without creating an object in a project for every step. Then, use fuse method of Part.Shape objects :
If you do want to have every step as a project object, as if you made it all in GUI, see chrisb's answer above. Just watch and bend what you see printed to py console when you do the gui stuff.
Code: Select all
sh1 = Part.makeCylinder(10,3)
sh2 = Part.makeSphere(5)
fused = sh1.fuse(sh2)
Part.show(fused)
Re: Python function for Union
Since we are on this topic, could you add either approach for a loft. I can't get the correct keywords.
Thank you
Thank you