From cb73a66c29fb7359228cc0a5227386fb40383b84 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Fri, 22 Oct 2021 00:48:41 -0400 Subject: [PATCH] Python script to (hopefully) automatically convert .csg files to .step --- scripts/csg2step.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 scripts/csg2step.py diff --git a/scripts/csg2step.py b/scripts/csg2step.py new file mode 100755 index 0000000..0d081da --- /dev/null +++ b/scripts/csg2step.py @@ -0,0 +1,43 @@ +#!/Applications/FreeCAD.app/Contents/Resources/bin/python + +# FROM https://forum.freecadweb.org/viewtopic.php?p=341824&sid=58456759bd632dffcf09baeeb397dcb6#p341824 + +import sys +import os + +if not len(sys.argv) == 3: + print("Usage: %s file.csg file.step" % sys.argv[0]) + sys.exit(1) + +file_input = sys.argv[1] +file_output = sys.argv[2] + +print("Converting %s to %s" % (file_input, file_output)) + +sys.path.append("/Applications/FreeCAD.app/Contents/Resources/lib") +import FreeCAD +import importCSG +import Part + +d = importCSG.open(file_input) + +o = [] + +# Select parent node +for i in d.Objects: + if not i.InList: + o.append(i) +print(len(o)) +quit() +# Perform the Fusion +App.activeDocument().addObject("Part::MultiFuse", "Fusion") +App.activeDocument().Fusion.Shapes = o +App.ActiveDocument.recompute() + +# Then the Refine +#App.ActiveDocument.addObject('Part::Feature','Refine').Shape=App.ActiveDocument.Fusion.Shape.removeSplitter() +#App.ActiveDocument.recompute() + +# Export as STEP +#Part.export([App.ActiveDocument.Refine], file_output) +Part.export([App.ActiveDocument.Fusion.Shape], file_output) \ No newline at end of file