diff --git a/step_to_obj_headless.py b/step_to_obj_headless.py new file mode 100644 index 0000000..be2da75 --- /dev/null +++ b/step_to_obj_headless.py @@ -0,0 +1,42 @@ +import os, sys +import FreeCAD as App +import Part +import Import +import MeshPart + +def convert(step_path, out_path, lin=0.1, ang=0.35): + doc = App.newDocument("conv") + Import.insert(os.path.abspath(step_path), doc.Name) + doc.recompute() + + shapes = [] + for o in doc.Objects: + if hasattr(o, "Shape") and o.Shape and not o.Shape.isNull(): + shapes.append(o.Shape) + + if not shapes: + raise RuntimeError("Keine Shapes gefunden.") + + compound = Part.makeCompound(shapes) if len(shapes) > 1 else shapes[0] + mesh = MeshPart.meshFromShape( + Shape=compound, LinearDeflection=lin, AngularDeflection=ang, Relative=False + ) + mesh.write(os.path.abspath(out_path)) + App.closeDocument(doc.Name) + +def main(argv): + #print(argv, len(argv)) + if len(argv) < 3: + print("Usage: FreeCADCmd script.py -- input.step output.stl [lin_defl] [ang_defl]") + return 1 + inp = argv[2] + out = argv[3] + lin = float(argv[4]) if len(argv) > 4 else 0.1 + ang = float(argv[5]) if len(argv) > 5 else 0.35 + convert(inp, out, lin, ang) + print(f"OK: {inp} -> {out}") + return 0 + +# WICHTIG: immer ausführen (FreeCAD setzt __name__ nicht zuverlässig auf "__main__") +raise SystemExit(main(sys.argv)) +