forked from SolidCode/SolidPython
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from solid import * | ||
|
||
scad = ScadInterface() | ||
|
||
scad.set_global_var("$fn", 6) | ||
|
||
scad.register_customizer_var("cyl_pos", "[1, 2, 3]") | ||
|
||
cube_pos = scad.get("cyl_pos") | ||
|
||
c = translate(cube_pos) ( | ||
cylinder(r=scad.inline("$t * 3"), h=scad.inline("$t * 10")) | ||
) | ||
|
||
scad_render_to_file(c, scad_interface=scad) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from .solidpython import OpenSCADObject | ||
|
||
class OpenSCADConstant(OpenSCADObject): | ||
def __init__(self, code): | ||
super().__init__("not valid openscad code !?!?!", {}) | ||
self.code = code | ||
|
||
def __repr__(self): | ||
return self._render() | ||
|
||
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 ScadInterface.inline(name) | ||
|
||
@staticmethod | ||
def inline(code): | ||
return scad_inline(code) | ||
|
||
def scad_inline(code): | ||
return OpenSCADConstant(code) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters