Importing Step via command line

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
greenbottle
Posts: 8
Joined: Tue Aug 31, 2021 7:31 pm

Importing Step via command line

Post by greenbottle »

Hello All,


I want to script a process and one step is to import an existing STEP file.

I tried method 1:

Code: Select all

   obj = App.ActiveDocument.addObject("Part::Feature","KICAD_pcb")
   obj.Shape = Part.read(u"mystepfile.step")
and method 2:

Code: Select all

import ImportGui
ImportGui.insert(u"mystepfile.step")

I prefer method 1 as I can use it without GUI. However, it imports the step as a single solid.
Method 2 shows all the parts in the step file (and is not a single solid).

How do I import with method 1 whilst retaining the individual parts of the STEP object.

Thanks.


Edit 1: Just discovered that I would use Insert instead of insertGUI

Code: Select all

v =  Import.insert(stepfilename, documentname)
This removes all the colour information from the step file somehow.

Code: Select all

OS: Ubuntu 20.04.4 LTS (XFCE/xubuntu)
Word size of FreeCAD: 64-bit
Version: 0.20.28872 (Git) AppImage
Build type: Release
Branch: (HEAD detached at 9057658)
Hash: 9057658ae5d638f6903bc831b53ceb349c2870a2
Python 3.9.12, Qt 5.12.9, Coin 4.0.0, OCC 7.5.3
Locale: English/United States (en_US)
Installed mods: 
  * kicadStepUpMod 10.12.0
  * Assembly4 0.11.12
  * InventorLoader 1.3.0
  * fasteners 0.3.40
Post Reply