Last active
November 29, 2023 20:34
-
-
Save sleemanj/b5c4b313fcc222345e38139b1154ab9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Convert a step file (or other) into a wrl file (or other) with FreeCAD | |
# You must provide an absolute input and output file path (NO RELATIVE!) | |
# A freecad window will open, the conversion will happen, and it will | |
# close. The export requires gui functions it seems so this is unavoidable. | |
# PROTIP: | |
# sudo startx -display :1 -- :1 vt8 | |
# CTRL-ALT-F8 to switch to the new X session on VT8 and run `xhost +` in the terminal | |
# CTRL-ALT-F7 back to your normal X session and then | |
# DISPLAY=:1 freecad-step-to-wrl.py [in] [out] | |
# the freecad window will open on the new XSession so doesn't interrupt you | |
# when you are doing a batch of them | |
import sys | |
inputFile = sys.argv[1] | |
outputFile = sys.argv[2] | |
sys.path.append("/usr/lib/freecad/lib"); | |
import FreeCADGui | |
FreeCADGui.showMainWindow() | |
import Import | |
import ImportGui | |
import Draft | |
FreeCAD.newDocument("Unnamed") | |
FreeCAD.setActiveDocument("Unnamed") | |
ImportGui.insert(inputFile,"Unnamed") | |
__objs__=[] | |
for part in FreeCAD.ActiveDocument.Objects: | |
__objs__.append(part) | |
FreeCADGui.export(__objs__,outputFile) | |
del __objs__ | |
FreeCAD.closeDocument("Unnamed") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great little utility.
To allow relative file paths (which is very useful), use ...
(not tested)