问题
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