Skip to content

ScadInterface #181

Description

@jeff-dh
#scad_interface.pyfrom .solidpythonimportOpenSCADObjectclassConstantOpenSCADObject(OpenSCADObject):
def__init__(self, code):
super().__init__("not valid openscad code !?!?!", {})
self.code=codedef_render(self, render_holes=42):
returnself.codeclassScadInterface:
def__init__(self):
self.header=''defregister_customizer_var(self, name, value, options=''):
self.header+=f'{name} = {value}; //{options}\n'defset_global_var(self, name, value):
self.header+=f'{name} = {value};\n'defget_header_str(self):
returnself.headerdefregister_font(self, filename):
self.header+=f'use <{filename}>\n'@staticmethoddefget(name):
returnself.inline(name)
@staticmethoddefinline(code):
returnscad_inline(code)
defscad_inline(code):
returnOpenSCADConstant(code)
#scad_renderdefscad_render(root, file_header='', scad_interface=None):
[...]
ifscad_interface!=None:
file_header+=scad_interface.get_header_str()
returnfile_header+includes+scad_body \
+extensions_footer_str

These 50 lines are able to close #180, #178, #165 and #61.

If possible I would not let OpenSCADConstant inherit from OpenSCADObject and use duck typing instead. But since the master is full of "typing-stuff" I'm afraid it'll crash it.

Example usage of the Interface:
customizer support
fonts
animation

This can also be used to set global $fn, $fa, $fs.

And I guess it would make the header parameter for scad_render obsolete, right?
Any thing else you would like to inject into the header can be done trough the ScadInterface.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions