Python script to automatically generate Step files

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
nasher128
Posts: 8
Joined: Fri Aug 21, 2020 2:28 pm

Python script to automatically generate Step files

Post by nasher128 »

Hi all.

I'm working on a personal project with contains many parts which I've created, around 25 parts. However, manually exporting each part to prepare my releases takes a while. Is there a Python script or any other method which I can run which automatically exports each part into a STL/STEP file, ready for 3D printing?

Thanks
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Python script to automatically generate Step files

Post by openBrain »

How are defined your 'parts'? Are these Part containers? Or just all top level objects? Or specific names?
nasher128
Posts: 8
Joined: Fri Aug 21, 2020 2:28 pm

Re: Python script to automatically generate Step files

Post by nasher128 »

Hi, thanks for the reply. They are specific names. There are no components, just used parts design -> and created a body for my part
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Python script to automatically generate Step files

Post by onekk »

It will be possible to generate automatically files from parts.

I use it to generate STL starting from drawings, but I'm coding all the models too.

What you are searching for is similar to this workflow?
  • select all the objects
  • invoke a Macro
  • Macro will generate STEP files starting from selected objects
Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Python script to automatically generate Step files

Post by openBrain »

nasher128 wrote: Fri Jan 21, 2022 10:42 pm Hi, thanks for the reply. They are specific names. There are no components, just used parts design -> and created a body for my part
Say you want to export each Body in a separate STEP :

Code: Select all

for obj in App.ActiveDocument.findObjects('PartDesign::Body'):
    obj.Shape.exportStep(f"/tmp/{obj.Label}.stp")
This snippet exports in /tmp/ folder and gives the Label of the Body as filename.
Post Reply