如何在solidpython中设置特殊变量$fa、$fs、$fn

如何在solidpython中设置特殊变量$fa、$fs、$fn,python,openscad,Python,Openscad,在中,演示了如何通过solidpython创建三维实体并将其保存到stl文件。由于未设置$fa、$fs、$fn,因此它们具有默认值,并且三维实体的面数较少。 上面线程中的示例代码: from solid import * from subprocess import run d = difference()( cube(10), sphere(15) ) scad_render_to_file(d, 'd.scad') run(["openscad", "-o", "d.st

在中,演示了如何通过solidpython创建三维实体并将其保存到stl文件。由于未设置$fa、$fs、$fn,因此它们具有默认值,并且三维实体的面数较少。 上面线程中的示例代码:

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"])
这里是生成的stl体 在中,我没有找到任何关于设置这些变量的内容。似乎已经过时了


如何在solidpython中设置$fa、$fs、$fn?

有两种方法

在solidpython中,某些对象(例如
circle()
sphere()
cyland()
)具有可选参数
segments
,对应于openscad中的
$fn
,请参见solidpython包(在archlinux/usr/lib/python/site packages/solid/objects.py上)中的objects.py文件中的源代码

可能的Python代码:

sphere(15, segments = 180)
scad_render_to_file(d, 'd.scad', file_header = '$fa = 0.1;\n$fs = 0.1;', include_orig_code=True)
生成的openscad代码:

sphere($fn = 180, r = 15);
或者,可以在
scad_render_to_file()
中设置文件头,请参阅solidpython包中solidpython.py文件中的源代码

solidpython代码:

sphere(15, segments = 180)
scad_render_to_file(d, 'd.scad', file_header = '$fa = 0.1;\n$fs = 0.1;', include_orig_code=True)
将以下行写入openscad文件的顶部:

$fa = 0.1;
$fs = 0.1;
这里是示例中得到的stl