This is very annoying, because if I right click on the individual solids to export them separately, the origin is not picked up, and so when loading the STLs on a new project, they are not in the right position:
Is there a workaround for this? E.g. some way to "force" FreeCAD to not use different origins for different compounds/shapes? Or some way to maintain the right positioning when exporting the STLs?
The alternative CadQuery package seems to do this correctly, but I'd prefer to use FreeCAD because of its versatility and additional utilities.
My end goal is to automate the STEP --> STLs conversion using Python. I'm currently using the following code (which works fine, other than the fact that the positioning is wrong, as mentioned above):
Code: Select all
def step2stl_fc(step_file="model.step", clear=True):
# Prepare FreeCAD STEP configuration
with open(os.getenv("HOME")+'/.FreeCAD/user.cfg', 'r') as file :
filedata = file.read()
filedata = filedata.replace('ReadShapeCompoundMode" Value="1', 'ReadShapeCompoundMode" Value="0')
with open(os.getenv("HOME")+'/.FreeCAD/user.cfg', 'w') as file:
file.write(filedata)
# Import FreeCAD
import FreeCAD
import Import
import Mesh
# 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")
# Export full model as a single STL
obj_list = []
for obj in FreeCAD.ActiveDocument.Objects:
if str(obj) == "<Part::PartFeature>" and obj.Shape.isClosed():
obj_list.append(obj)
def getObj(object):
return FreeCAD.getDocument("Unnamed").getObject(str(object.Name))
__objs__ = list(map(getObj, obj_list))
Mesh.export(__objs__, "data/tmp/model.stl")
# Export each object as a separate STL
for object in obj_list:
if object.Name.startswith("Part"):
obj = FreeCAD.getDocument("Unnamed").getObject(str(object.Name))
Mesh.export([obj], "data/" + str(object.Label) + ".stl")