Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #146 from adam-urbanczyk/master
Browse files Browse the repository at this point in the history
Symmetric extrude with respect to the workplane. Thanks adam!
  • Loading branch information
dcowden committed May 23, 2016
2 parents bcea03d + 58683d0 commit b41d52f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cadquery/cq.py
Original file line number Diff line number Diff line change
Expand Up @@ -1967,14 +1967,15 @@ def twistExtrude(self, distance, angleDegrees, combine=True, clean=True):
if clean: newS = newS.clean()
return newS

def extrude(self, distance, combine=True, clean=True):
def extrude(self, distance, combine=True, clean=True, both=False):
"""
Use all un-extruded wires in the parent chain to create a prismatic solid.
:param distance: the distance to extrude, normal to the workplane plane
:type distance: float, negative means opposite the normal direction
:param boolean combine: True to combine the resulting solid with parent solids if found.
:param boolean clean: call :py:meth:`clean` afterwards to have a clean shape
:param boolean both: extrude in both directions symmetrically
:return: a CQ object with the resulting solid selected.
extrude always *adds* material to a part.
Expand All @@ -1990,8 +1991,9 @@ def extrude(self, distance, combine=True, clean=True):
Support for non-prismatic extrusion ( IE, sweeping along a profile, not just
perpendicular to the plane extrude to surface. this is quite tricky since the surface
selected may not be planar
"""
r = self._extrude(distance) # returns a Solid (or a compound if there were multiple)
"""
r = self._extrude(distance,both=both) # returns a Solid (or a compound if there were multiple)

if combine:
newS = self._combineWithBase(r)
else:
Expand Down Expand Up @@ -2254,11 +2256,12 @@ def loft(self, filled=True, ruled=False, combine=True):

return self.newObject([r])

def _extrude(self, distance):
def _extrude(self, distance, both=False):
"""
Make a prismatic solid from the existing set of pending wires.
:param distance: distance to extrude
:param boolean both: extrude in both directions symmetrically
:return: a FreeCAD solid, suitable for boolean operations.
This method is a utility method, primarily for plugin and internal use.
Expand Down Expand Up @@ -2305,6 +2308,10 @@ def _extrude(self, distance):
for ws in wireSets:
thisObj = Solid.extrudeLinear(ws[0], ws[1:], eDir)
toFuse.append(thisObj)

if both:
thisObj = Solid.extrudeLinear(ws[0], ws[1:], eDir.multiply(-1.))
toFuse.append(thisObj)

return Compound.makeCompound(toFuse)

Expand Down
24 changes: 24 additions & 0 deletions tests/TestCadQuery.py
Original file line number Diff line number Diff line change
Expand Up @@ -1387,3 +1387,27 @@ def testEnclosure(self):
result =topOfLid.union(bottom)

self.saveModel(result)

def testExtrude(self):
"""
Test symmetric extrude
"""
r = 1.
h = 1.
decimal_places = 9.

#extrude symmetrically
s = Workplane("XY").circle(r).extrude(h,both=True)

top_face = s.faces(">Z")
bottom_face = s.faces("<Z")

#calculate the distance between the top and the bottom face
delta = top_face.val().Center().sub(bottom_face.val().Center())

self.assertTupleAlmostEquals(delta.toTuple(),
(0.,0.,2.*h),
decimal_places)



0 comments on commit b41d52f

Please sign in to comment.