-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Some way to inline literal OpenSCAD code #178
Comments
class ConstantOpenSCADObject(OpenSCADObject):
def __init__(self, code):
super().__init__("not reander able", {})
self.code = code
def _render(self, render_holes=42):
return self.code
def scad_inline(code):
return ConstantOpenSCADObject(code) You should be able to just plug this into your code in "user space" and use it. This is not 100% clean, because OpenSCADObject contains a lot of stuff not needed for ConstantOpenSCADObject but since there's no other base class...... You might also leave the inheritance away and just plug a duck typing class with _render into it. (set_modifier or similar will not work with tihs, but I think it also makes not a lot sense to make it work) Another solution could be to use py2openscad. When ever you render a child, don't call _render, but call py2openscad. If it's a OpenSCADObject it calls _render anyway but if it's just a string it return's it......... this should also work. But I don't think you'll gain a lot with this..... I'm not really into these customizer stuff but mixing OpenSCAD and SolidPython code -- I think -- will never work properly. Isn't this the same as if you would create a .scad file that contains:
import it with SolidPython and call |
Update: The Here's a working (but therefor hacky version): from solid import *
class ConstantOpenSCADObject(IncludedOpenSCADObject):
def __init__(self, code):
self._get_include_path = lambda x : ''
super().__init__("not reander able", {}, "blablub")
self.include_string = ''
self.code = " " + code + " "
def _render(self, render_holes=42):
return self.code
def scad_inline(code):
return ConstantOpenSCADObject(code) |
With the impending arrival (fingers crossed) of Customizer support for #61, some features of SolidPython won't play nicely with customizer values. For example:
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 ascad_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:
I'm not sure how I should build this yet, but I don't think it should take too much work
The text was updated successfully, but these errors were encountered: