Skip to main content
 首页 » 编程设计

python之在 Python 中将 scad 文件格式转换为 STL

2024年10月01日7zfyouxi

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

我尝试在互联网上搜索一些库,但找不到任何合适的库(我使用的是 Windows 操作系统)有人知道吗?

请您参考如下方法:

您可以从命令行运行 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 应该替换为 subprocess.run()