From a50311ec78f0277ba4ab544cbb26b42225f98fbd Mon Sep 17 00:00:00 2001 From: Juergen Weigert Date: Tue, 13 Jun 2017 12:05:53 +0200 Subject: [PATCH] Expose scale feaure of openSCAD's extrude_linear() function for conical or pyramidal objects. --- paths2openscad.inx | 6 +++++- paths2openscad.py | 21 +++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/paths2openscad.inx b/paths2openscad.inx index c3c3c11..4b2ed44 100755 --- a/paths2openscad.inx +++ b/paths2openscad.inx @@ -80,6 +80,10 @@ from all normal objects. raise: XXX mm Move the object upwards to create a hole (with 'a') or balcony. +scale: 90 % + Taper the object along its height. The top surface is scaled to this value, + while the bottom surface remains as drawn. + Note that the description has preference over ID. Otherwise, the height parameter is used. @@ -104,7 +108,7 @@ to millimeters using the SVG Standard's definition of 90 pixels = 1 inch -- since inkscape 0.92: 96 pixels = 1 inch. -v0.15 +v0.16 Dan Newman (dan newman @ mtbaldy us) Josef Skladanka (jskladan @ redhat com) Juergen Weigert (juergen @ fabmail org) diff --git a/paths2openscad.py b/paths2openscad.py index 39b79d0..c601978 100755 --- a/paths2openscad.py +++ b/paths2openscad.py @@ -45,6 +45,9 @@ # Subpath in subpath are now handled very nicely. # Added msg_extrude_by_hull_and_paths() outline mode with nested paths. # +# 2017-06-12, juergen@fabmail.org +# 0.16 Feature added: scale: XXX to taper the object while extruding. +# # CAUTION: keep the version numnber in sync with paths2openscad.inx about page # CAUTION: indentation and whitespace issues due to pep8 compatibility. @@ -82,6 +85,9 @@ RE_AUTO_HEIGHT_DESC = re.compile( r"^(?:ht|[Hh]eight):\s*([aA]?\d+(?:\.\d+)?) ?mm$", re.MULTILINE) +RE_AUTO_SCALE_DESC = re.compile( + r"^(?:sc|[Ss]cale):\s*(\d+(?:\.\d+)?) ?%$", + re.MULTILINE) RE_AUTO_RAISE_DESC = re.compile( r"^(?:[Rr]aise|[Oo]ffset):\s*(\d+(?:\.\d+)?) ?mm$", re.MULTILINE) @@ -277,13 +283,13 @@ def subdivideCubicPath(sp, flat, i=1): def msg_linear_extrude(id, prefix): - msg = ' linear_extrude(height=h)\n' + \ + msg = ' linear_extrude(height=h, scale=0.01*s)\n' + \ ' polygon(%s_%d_points);\n' % (id, prefix) return msg def msg_linear_extrude_by_paths(id, prefix): - msg = ' linear_extrude(height=h)\n' + \ + msg = ' linear_extrude(height=h, scale=0.01*s)\n' + \ ' polygon(%s_%d_points, %s_%d_paths);\n' % \ (id, prefix, id, prefix) return msg @@ -648,6 +654,9 @@ def object_merge_auto_values(auto, node): height = RE_AUTO_HEIGHT_DESC.findall(desc_node.text) if height: auto['height'] = height[-1] + zscale = RE_AUTO_SCALE_DESC.findall(desc_node.text) + if zscale: + auto['scale'] = zscale[-1] zraise = RE_AUTO_RAISE_DESC.findall(desc_node.text) if zraise: auto['raise'] = zraise[-1] @@ -757,19 +766,19 @@ def object_merge_auto_values(auto, node): prefix += 1 # #### end global data for msg_*() functions. #### - self.f.write('module poly_' + id + '(h, w, res=line_fn)\n{\n') + self.f.write('module poly_' + id + '(h, w, s, res=line_fn)\n{\n') self.f.write(' scale([25.4/%g, -25.4/%g, 1]) union()\n {\n' % (self.dpi, self.dpi)) # And add the call to the call list # Height is set by the overall module parameter # unless an auto-height is found. - auto = {'height': 'h', 'raise': '0', 'neg': False} + auto = {'height': 'h', 'raise': '0', 'scale': 100.0, 'neg': False} if self.options.autoheight == 'true': object_merge_auto_values(auto, node) - call_item = 'translate ([0,0,%s]) poly_%s(%s, min_line_mm(%s));\n' % ( - auto['raise'], id, auto['height'], stroke_width_mm) + call_item = 'translate ([0,0,%s]) poly_%s(%s, min_line_mm(%s), %s);\n' % ( + auto['raise'], id, auto['height'], stroke_width_mm, auto['scale']) if auto['neg']: self.call_list_neg.append(call_item)