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

Converting scad file format to stl in Python

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

我尝试在 Internet 上搜索一些库,但找不到任何合适的库(我正在使用 Windows OS)有人知道吗?

您可以 运行 从命令行打开 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()