Open
Description
#scad_interface.py
from .solidpython import OpenSCADObject
class ConstantOpenSCADObject(OpenSCADObject):
def __init__(self, code):
super().__init__("not valid openscad code !?!?!", {})
self.code = code
def _render(self, render_holes=42):
return self.code
class ScadInterface:
def __init__(self):
self.header = ''
def register_customizer_var(self, name, value, options=''):
self.header += f'{name} = {value}; //{options}\n'
def set_global_var(self, name, value):
self.header += f'{name} = {value};\n'
def get_header_str(self):
return self.header
def register_font(self, filename):
self.header += f'use <{filename}>\n'
@staticmethod
def get(name):
return self.inline(name)
@staticmethod
def inline(code):
return scad_inline(code)
def scad_inline(code):
return OpenSCADConstant(code)
#scad_render
def scad_render(root, file_header = '', scad_interface=None):
[...]
if scad_interface != None:
file_header += scad_interface.get_header_str()
return file_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
Labels
No labels