Skip to content

Commit

Permalink
removed special _fn handling in header -> ScadInterface, better ScadI…
Browse files Browse the repository at this point in the history
…nterface integration
  • Loading branch information
jeff-dh committed Jun 1, 2021
1 parent b5abd32 commit fa1cbfc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
11 changes: 7 additions & 4 deletions solid/core/object_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ def __call__(self, *args):
def __repr__(self):
return self.as_scad()

def as_scad(self, _fn=None):
def as_scad(self, scad_interface=None):
from .scad_render import scad_render
return scad_render(self, _fn=_fn)[:-1]
return scad_render(self, scad_interface=scad_interface)[:-1]

def save_as_scad(self, filename='', outdir='', _fn=None):
def save_as_scad(self, filename='', outdir='', scad_interface=None):
from .scad_render import scad_render_to_file
return scad_render_to_file(self, filename, outdir, _fn=_fn)
return scad_render_to_file(self,
filename,
outdir,
scad_interface=scad_interface)

class OpenSCADObject(ObjectBase):
def __init__(self, name, params):
Expand Down
9 changes: 3 additions & 6 deletions solid/core/scad_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# =========================================
# = Rendering Python code to OpenSCAD code=
# =========================================
def scad_render(root, file_header = '', _fn=None, scad_interface=None):
def scad_render(root, file_header = '', scad_interface=None):
#get a list of all used and included files
includes = get_include_string()

Expand All @@ -26,24 +26,21 @@ def scad_render(root, file_header = '', _fn=None, scad_interface=None):
extensions_footer_str = default_extension_manager.call_post_render(root)
extensions_footer_str += "\n" if extensions_footer_str else ''

if _fn:
file_header += f'$fn = {_fn};\n\n'

if scad_interface != None:
file_header += scad_interface.get_header_str()

return file_header + includes + extensions_header_str + scad_body \
+ extensions_footer_str

def scad_render_to_file(scad_object, filename=None, out_dir='',
file_header='', include_orig_code=True, _fn=None,
file_header='', include_orig_code=True,
scad_interface = None):

if out_dir == None:
out_dir = ''
header = f"// Generated by ExpSolidPython\n" + file_header + "\n"

rendered_string = scad_render(scad_object, header, _fn, scad_interface)
rendered_string = scad_render(scad_object, header, scad_interface)

return _write_to_file(rendered_string, filename, out_dir)

Expand Down
3 changes: 1 addition & 2 deletions solid/examples/11-fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@
scad = ScadInterface()
scad.register_font("11-font/RichEatin.otf")

t = text(font="Rich Eatin'", text="blablub")
scad_render_to_file(t, scad_interface=scad)
text(font="Rich Eatin'", text="blablub").save_as_scad(scad_interface=scad)

0 comments on commit fa1cbfc

Please sign in to comment.