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"])
您可以在 openscad 中打开 d.scad,渲染它(按 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屋!