-
Notifications
You must be signed in to change notification settings - Fork 184
Description
With the impending arrival (fingers crossed) of Customizer support for #61, some features of SolidPython won't play nicely with customizer values. For example:
from solid import cube, scad_render_to_file
from solid.utils import right
from solid.customizer import CustomizerSliderFloat
object_count = CustomizerSlider('objects', 2, 1, 10, step=1)
side = 2
objs = [right(2*i*side)(cube(side)) for i in range(object_count)] # we want this to use a reactive slider value but it can't :-/
all_objs = union()(objs)
scad_render_to_file(all_objs, 'customizer_fail.scad')
This will create an OpenSCAD file with a slider, objects
from 1 to 10. But, because the list comprehension (objs = [right(...]
) happens only in Python code, the SCAD file will only use the initial value of the slider no matter how a user changes the slider in OpenSCAD.
If we want a row of cubes that reacts to the OpenSCAD slider, we need to run the object connection loop in OpenSCAD itself. One way to do this would be a dedicated scad_loop()
function we could add. But we might also add a scad_inline()
function that would just paste an OpenSCAD string directly into the output .scad
file without translating at all. That should make us able to use Customizer values anywhere, however we like.
Proposed fix:
from solid import cube, scad_render_to_file, scad_inline
from solid.utils import right
from solid.customizer import CustomizerSliderFloat
object_count = CustomizerSlider('objects', 2, 1, 10, step=1)
side = 2
objs = scad_inline('''
for (i = [1:objects]){
translate([2*i*side,0,0]){
cube(side);
}
}
''')
all_objs = union()(objs)
scad_render_to_file(all_objs, 'customizer_fail.scad')
I'm not sure how I should build this yet, but I don't think it should take too much work