利用python实现 CAD STEP格式转化为STL格式--update 对整个文件夹下的所有文件进行转换格式

update

# 导入FreeCAD 路径为FreeCAD安装路径,bin文件里有个文件叫 FreeCad.pyd 这是关键
import sys
sys.path.append('C:\\Software\\FreeCAD 0.17\\bin')
import FreeCAD     # 然后就可以导入CAD了

import math
import Part
import Mesh

# 增加了以下这些代码 
import os
dir = "D:\\work\\step\\"
for root, dirs, files in os.walk(dir):
    for file in files:
        # print (os.path.join(root,file))
        # print(file)
        # list.append(file)
        stp = "D:\\work\\step\\{}".format(file)
        stl = "D:\\work\\stl\\{}.stl".format(file)

        print(stp)
        print(stl)

        shape = Part.Shape()
        shape.read(stp)
        mesh = Mesh.Mesh()
        mesh.addFacets(shape.tessellate(0.01))
        mesh.write(stl)

猜你喜欢

转载自blog.csdn.net/Two_Brother/article/details/81181797