in a previous thread is shown, how to create a 3D-body and save it to an stl-file by solidpython. As $fa, $fs, $fn are not set they have the default values and the 3D-body has a low number of facets. The example code from the thread above:
from solid import *
from subprocess import run
d = difference()(
cube(10),
sphere(15)
)
scad_render_to_file(d, 'd.scad')
run(["openscad", "-o", "d.stl", "d.scad"])
Here the resulting stl-body
In the documentation i didn‘t find anything about setting these variables. This readme seems to be obsolete.
How can i set $fa, $fs, $fn in solidpython?
There are two ways to do it.
In solidpython some objects (eg. circle()
, sphere()
, cylinder()
) have the optional parameter segments
corresponding to $fn
in openscad, see the source code in the file objects.py in the solidpython package (on archlinux /usr/lib/python/site-packages/solid/objects.py).
possible solidpython code:
sphere(15, segments = 180)
resulting openscad code:
sphere($fn = 180, r = 15);
Alternatively a file header can be set in scad_render_to_file()
, see the source code in the file solidpython.py in the solidpython package.
solidpython code:
scad_render_to_file(d, 'd.scad', file_header = '$fa = 0.1;\n$fs = 0.1;', include_orig_code=True)
writes these lines to the top of the openscad file:
$fa = 0.1;
$fs = 0.1;