python固态处理后如何将数据保存在stl文件中? [英] how to save data in stl file after python solid processing?
问题描述
我需要在python上处理openscad程序。我使用实体库( https://solidpython.readthedocs.io/en/latest/index .html ),但在处理后我没有找到任何保存数据的方法。示例
I need to process openscad programs on python. I use solid library (https://solidpython.readthedocs.io/en/latest/index.html) but I haven't found any method to save data after process. Example
from solid import *
d = difference()(
cube(10),
sphere(15)
)
我需要保存 d 到stl文件的变量。这个怎么做?而且,如果有更好的库,我需要建议哪种库更好用。
I need to save d variable to stl file. How to do this? And if there's better library, I need advice what library better to use.
推荐答案
您需要openscad将数据导出为stl文件。您可以从python代码中执行以下操作:
You need openscad to export data as stl-file. You can do this from python-code:
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"])
而不是最后一步,您可以打开d.scad在openscad中,进行渲染(按F6键)并将其导出为STL或在控制台中运行:
instead of last step you can open d.scad in openscad, render it (press F6) and export it as STL or run in console:
openscad -o d.stl d.scad
从命令行使用openscad请参见文档
the use of openscad from command line see documentation
这篇关于python固态处理后如何将数据保存在stl文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!