Code: Select all
def step2stl(step_file="model.step", clear=True):
doc = FreeCAD.newDocument("Unnamed")
# Delete pre-existing STL files
dir_name = "data"
test = os.listdir(dir_name)
for item in test:
if item.endswith(".stl"):
os.remove(os.path.join(dir_name, item))
# Empty out tmp directory
if clear:
dir = "data/tmp"
if os.path.exists(dir):
shutil.rmtree(dir)
os.makedirs(dir)
# Import STEP file
Import.insert("data/" + step_file, "Unnamed")
obj_list = []
for obj in FreeCAD.ActiveDocument.Objects:
if hasattr(obj, "Shape"):
obj_list.append(obj.Name)
__objs__ = []
for object in obj_list:
__objs__.append(FreeCAD.getDocument("Unnamed").getObject(str(object)))
Mesh.export(__objs__, "data/tmp/model.stl")
del __objs__
for object in obj_list:
__objs__ = []
if object.startswith("Part"):
__objs__.append(FreeCAD.getDocument("Unnamed").getObject(str(object)))
Mesh.export(__objs__, "data/" + str(object) + ".stl")
del __objs__
There is a different origin associated with each object, and if I export each STL separately, and then import them one by one, I get this offset:
This happens with both the GUI fashion of importing and exporting, as well as the scripting way. Is there a way to tell FreeCAD to convert everything so that it uses a single global origin, so that my exported STL files remain intact (just like I nicely see it on FreeCAD's interface when I import the STEP file)?