From 633dc86f6b6f906904ce8736f6e9e2fc1f64f5af Mon Sep 17 00:00:00 2001 From: adam-urbanczyk Date: Tue, 9 Nov 2021 18:35:00 +0100 Subject: [PATCH] Allow to use Edge/Wire for sweep --- cadquery/cq.py | 15 +++++++++++---- tests/test_cadquery.py | 5 +++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cadquery/cq.py b/cadquery/cq.py index 128d3f84e..7b754fff3 100644 --- a/cadquery/cq.py +++ b/cadquery/cq.py @@ -3106,7 +3106,7 @@ def revolve( def sweep( self: T, - path: "Workplane", + path: Union["Workplane", Wire, Edge], multisection: bool = False, sweepAlongWires: Optional[bool] = None, makeSolid: bool = True, @@ -3142,8 +3142,15 @@ def sweep( ) r = self._sweep( - path.wire(), multisection, makeSolid, isFrenet, transition, normal, auxSpine + path.wire() if isinstance(path, Workplane) else path, + multisection, + makeSolid, + isFrenet, + transition, + normal, + auxSpine, ) # returns a Solid (or a compound if there were multiple) + newS: T if combine: newS = self._combineWithBase(r) @@ -3632,7 +3639,7 @@ def _revolve( def _sweep( self, - path: "Workplane", + path: Union["Workplane", Wire, Edge], multisection: bool = False, makeSolid: bool = True, isFrenet: bool = False, @@ -3657,7 +3664,7 @@ def _sweep( toFuse = [] - p = path.val() + p = path.val() if isinstance(path, Workplane) else path if not isinstance(p, (Wire, Edge)): raise ValueError("Wire or Edge instance required") diff --git a/tests/test_cadquery.py b/tests/test_cadquery.py index 7cdbb511d..eadecd8d0 100644 --- a/tests/test_cadquery.py +++ b/tests/test_cadquery.py @@ -1015,6 +1015,11 @@ def testSweep(self): self.assertEqual(3, result.faces().size()) self.assertEqual(3, result.edges().size()) + # Test Wire path + result = Workplane("XY").circle(1.0).sweep(path.val()) + self.assertEqual(3, result.faces().size()) + self.assertEqual(3, result.edges().size()) + # Test with makeSolid False result = Workplane("XY").circle(1.0).sweep(path, makeSolid=False) self.assertEqual(1, result.faces().size())