Skip to main content

Export Multiple Selected to Multiple STEP Files in One Go - FreeCAD Macro

FreeCAD is a powerful open-source CAD tool used by engineers and designers worldwide. If you need to export multiple selected objects to separate files, this handy macro can save you time and effort.  This macro will take the selected objects i.e. a number of separate extrudes that you have ctrl selected from screen, and export them out as individual step files into your chosen directory.  A demonstration of this macro can be found on my youtube channel  https://youtu.be/IapVaYQWN2M. To use the macro take a copy of the below text.

Macro Code

from PySide import QtGui

folder = str(QtGui.QFileDialog.getExistingDirectory(None, "Select Directory"))
a = Gui.Selection.getSelection()
count = 0
import ImportGui
options = None
if hasattr(ImportGui, "exportOptions"):
options = ImportGui.exportOptions(".step")
for b in a:
objs = []
objs.append(b)
file = folder+"/"+str(count)+".step"
ImportGui.export(objs, file, options)
count = count + 1


Load freeCAD and from the top menu select macro > macros.  You will see the Execute Macro popup.


Click on the create button and give your macro a name in the popup that follows.


Click OK.  A new window will appear where you can paste the macro into it and save (ctrl s or top menu > file > save).


The macro is now ready to use.

Using the macro

An example of using the macro.  Let's say we create a project with two cubes within.  Shift or ctrl select both cubes from the treeview so they are both selected.


Select top menu > Macro > macros and then select the macro from the popup window.


Click on the execute button to run the macro.  The popup will close and you will see the next window will ask you for the location of where you want to export the individual step files to.



Click the choose button and the window closes followed by the step file options.  Select the options you want if needed.


Click OK.  Navigate to the folder which was chosen and you will find the files of each item you selected in the treeview.


You now have all your exported step files.














Comments

  1. You know me as Felsin Ferguson over on Youtube - Following up on my reply to your reply on this macro in the comments.

    I think everybody can agree that we can do better than naming the files "0.stl", "1.stl", etc... So I took the liberty of doing a fiddle, and here's my version for doing multiple STL exports - Released to the public domain, yadda, yadda, whatever.

    from PySide import QtGui

    folder = str(QtGui.QFileDialog.getExistingDirectory(None, "Select Directory"))
    a = Gui.Selection.getSelection()

    import Mesh

    for b in a:
    objs = []
    objs.append(b)
    Mesh.export(objs, folder+"/"+b.Label+".stl")

    And I see now why the objs = [] is inside the for loop. Guess my nose was a bit "off" :)

    ReplyDelete
    Replies
    1. Ugh... Looks like it ate the indentation. Should be everything flush-left up to and including the "for" line, and the next 3 lines need one indent each.

      Delete
    2. from PySide import QtGui

      folder = str(QtGui.QFileDialog.getExistingDirectory(None, "Select Directory"))
      a = Gui.Selection.getSelection()

      import Mesh
      options = None
      if hasattr(Mesh, "exportOptions"):
      options = Mesh.exportOptions(".stl")
      for b in a:
      objs = []
      objs.append(b)
      file = folder+"/"+b.Label+".stl"
      Mesh.export(objs, file)

      I was thinking the same thing also.

      Delete

Post a Comment

Popular posts from this blog

Beginners FreeCAD: Exercise 5.1 & 5.2 (Reference Images)

Welcome to the total beginners course to FreeCAD 0.20. In this is a two part lesson we will practice our tracing skill in the form of a mini project. Using the below reference photos we will create a more complex part which will consist of repeating features. We will utilise the symmetry tools to ease construction in both FreeCAD sketcher and Part Design workbench. This project work will help teach the fundamentals of freeCAD allowing a understanding of the basics but delivering this information via teaching you different workflows. In this tutorial we will be tracing photos imported into FreeCAD via the image workbench https://wiki.freecadweb.org/Image_Workbench JUMP TO IMAGES Do you want to purchase the complete series along with others and keep forever?  Check out my shop https://ko-fi.com/mang0/shop The story of this tutorial The idea and first attempt at creating this tutorial was back in FreeCAD 0.18.  The physical part itself, well, I have no idea what really it is, i...

FreeCAD For Beginners: CAD Thinking Part 1

Step-by-Step CAD Thinking FreeCAD Tutorial: Modeling a Latch Part (Part 1) Learning how to turn real life objects into CAD Models. Using FreeCAD we explain at a beginner level how to break down a physical object into its primitive shapes to digitise it into a 3D model, with this episode we are looking at a multi-part assembly, modelling each piece individually. The series aims to open your eyes and mind giving you the ground skills to pick the correct profiles, geometry and workflow when it comes to modelling your parts. This is not just for FreeCAD but for all CAD packages out there. Introduction This tutorial is the first in a series guiding you through modeling a latch assembly in FreeCAD (version 0.21) using the Part Design and A2Plus workbenches. It focuses on modeling the first part (a slotted component) by selecting the top profile to create a slot and adding side arcs, emphasizing CAD thinking to break down complex shapes into primitives. The tutorial highlights model stability...

Beginner FreeCAD Tutorial 14: Reference Document for Exercise 1

This tutorial focuses on modelling a deck eye plate. These items are normally made of stainless steel with some kind of galvanised coating to stop corrosion. They are used in many industries but are most commonly found around boats, ships, sail lofts and docks where they play an important part in marine industry. Finding their use in many applications, they are often wall mounted acting as lashing points for mooring and for tying down sails or canopies. They can even be used for domestic use around the house and garden, for example to anchor ropes, cords and lines. So if your into 3D printing your finished creations, you can make use of the finished result.   Disclaimer : The strength of the part will depend on the internal structure, settings of the slicer and the material it has been printed on.  This will limit its application as failure of the part, damage to property and injury is a possibility.  These items are normally made of steel and are tested to take a...