I am working on a project in which I have to convert a .dae file to .stl file. I am using the code given below
import sys
sys.path.insert(0, "C:\\Program Files (x86)\\FreeCAD 0.17\\bin\\")
import FreeCAD
import Part
import Mesh
shape = Part.Shape()
shape.read('INPUTFILE.dae')
doc = App.newDocument('Doc')
pf = doc.addObject("Part::Feature","MyShape")
pf.Shape = shape
Mesh.export([pf], 'OUTPUTFILE.stl')
I get an error when the interpreter tries to execute the command shape.read('INPUTFILE.dae'). According to this the code should be able to handle .dae input files. The error I get is concerning invalid input file format:
shape.read('INPUTFILE.dae')
FreeCADError: {'swhat': 'Unknown extension', 'sfunction': '', 'btranslatable': False, 'sfile': '', 'sclassname': 'class Base::Exception', 'breported': True, 'sErrMsg': 'Unknown extension', 'iline': 0}
I also have pycollada installed on the system.
Does anyone know how to tackle this problem?
You need to pip install pycollada. Then in your code, import importDAE and then insert the shape file.
When you insert it, you'll get a new document object whose Mesh property contains the shape. Then you can export the mesh as an stl.
Something like below.
BTW, I figured this out by doing it in the GUI and looking at the python console. All the commands are there and I just had to adapt them to a script.
import sys
sys.path.insert(0, '/home/brad/FCD/FC/lib')
import FreeCAD
import Part
import Mesh
import importDAE
doc = App.newDocument('Doc')
newobj = importDAE.insert(u"/home/brad/Desktop/efdae.dae","Unnamed1")
Mesh.export([newobj.Mesh], 'my_shape.stl')