how to save data in stl file after python solid processing?

不打扰是莪最后的温柔 提交于 2019-12-24 18:49:41

问题


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)
)

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.


回答1:


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"])

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

the use of openscad from command line see documentation



来源:https://stackoverflow.com/questions/54040390/how-to-save-data-in-stl-file-after-python-solid-processing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!