在Python中将scad文件格式转换为stl格式

2024-03-29 10:55:38 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有一种方法可以在Python中有效地将SCAD文件转换成STL格式?我有大约3000个文件要转换成STL。另外,还有一些不同的格式。在

我试着在因特网上搜索一些库,但是没有找到合适的库(我正在使用Windows操作系统),有人知道吗?在


Tags: 文件方法windows格式因特网stlscad
1条回答
网友
1楼 · 发布于 2024-03-29 10:55:38

您可以从命令行运行openscad,请参见documentation, 并用python编写每个命令(python3中的示例)

from os import listdir
from subprocess import call

files = listdir('.')
for f in files:
    if f.find(".scad") >= 0:            # get all .scad files in directory
        of = f.replace('.scad', '.stl') # name of the outfile .stl
        cmd = 'call (["openscad",  "-o", "{}",  "{}"])'.format(of, f)   #create openscad command
        exec(cmd)

在python3.5及更高版本中,subprocess.call应该被subrocess.run()代替

相关问题 更多 >