本文介绍了FreeCAD shape.read()错误:不支持的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,我必须将.dae文件转换为.stl文件.我正在使用下面给出的代码

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')

解释器尝试执行命令shape.read('INPUTFILE.dae')时出现错误.根据,该代码应能够处理.dae输入文件. .我收到的错误与无效的输入文件格式有关:

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}

我还在系统上安装了pycollada.

I also have pycollada installed on the system.

有人知道如何解决这个问题吗?

Does anyone know how to tackle this problem?

推荐答案

您需要pip安装pycollada.然后在您的代码中,导入importDAE,然后插入形状文件.

You need to pip install pycollada.Then in your code, import importDAE and then insert the shape file.

插入时,您将获得一个新的文档对象,该对象的Mesh属性包含该形状.然后,您可以将网格导出为stl.

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.

类似下面的内容.

顺便说一句,我通过在GUI中进行操作并查看python控制台来解决了这一问题.所有命令都在那里,我只需要使它们适应脚本即可.

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')

这篇关于FreeCAD shape.read()错误:不支持的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 04:10