Skip to content

Commit

Permalink
Expose scale feaure of openSCAD's extrude_linear() function for conic…
Browse files Browse the repository at this point in the history
…al or pyramidal objects.
  • Loading branch information
Juergen Weigert committed Jun 13, 2017
1 parent 6ec50a4 commit a50311e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
6 changes: 5 additions & 1 deletion paths2openscad.inx
Original file line number Diff line number Diff line change
Expand Up @@ -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.</_param>
Expand All @@ -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)
Expand Down
21 changes: 15 additions & 6 deletions paths2openscad.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, [email protected]
# 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.

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a50311e

Please sign in to comment.