Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 923
Alex Kolmogorov Avatar asked Apr 14 '26 17:04

Alex Kolmogorov


1 Answers

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

like image 165
a_manthey_67 Avatar answered Apr 17 '26 08:04

a_manthey_67