我需要在 python 上处理 openscad 程序。我使用实体库(https://solidpython.readthedocs.io/en/latest/index.html),但我还没有找到任何在处理后保存数据的方法。例子
from solid import *
d = difference()(
cube(10),
sphere(15)
)
我需要将d变量保存到 stl 文件。这个怎么做?如果有更好的图书馆,我需要建议更好地使用哪个图书馆。
我需要在 python 上处理 openscad 程序。我使用实体库(https://solidpython.readthedocs.io/en/latest/index.html),但我还没有找到任何在处理后保存数据的方法。例子
from solid import *
d = difference()(
cube(10),
sphere(15)
)
我需要将d变量保存到 stl 文件。这个怎么做?如果有更好的图书馆,我需要建议更好地使用哪个图书馆。
您需要 openscad 将数据导出为 stl 文件。您可以从 python 代码执行此操作:
from solid import *
# to run openscad
from subprocess import run
d = difference()(
cube(10),
sphere(15)
)
# generate valid openscad code and store it in file
scad_render_to_file(d, 'd.scad')
# run openscad and export to stl
run(["openscad", "-o", "d.stl", "d.scad"])
除了最后一步,您可以在 openscad 中打开 d.scad,对其进行渲染(按 F6)并将其导出为 STL 或在控制台中运行:
openscad -o d.stl d.scad
从命令行使用 openscad 参见文档