From cac5cf92f18d6ee44497d9faddd82082a5f367cc Mon Sep 17 00:00:00 2001 From: Aaron Peterson Date: Thu, 15 Oct 2020 14:10:49 -0500 Subject: [PATCH] Create a child workplane on a vertex (#480) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add parent face detection to workplane() * Update cq.py * add nonetype check and tests * fixed test formatting * mypy fix attempt Co-authored-by: Adam UrbaƄczyk --- cadquery/cq.py | 10 ++++++++-- tests/test_cadquery.py | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cadquery/cq.py b/cadquery/cq.py index 27955084..e4aa35ac 100644 --- a/cadquery/cq.py +++ b/cadquery/cq.py @@ -543,8 +543,14 @@ class Workplane(object): if isinstance(obj, Shape) else obj.Center() ) - normal = self.plane.zDir - xDir = self.plane.xDir + + val = self.parent.val() if self.parent else None + if isinstance(val, Face): + normal = val.normalAt(center) + xDir = _computeXdir(normal) + else: + normal = self.plane.zDir + xDir = self.plane.xDir else: raise ValueError("Needs a face or a vertex or point on a work plane") diff --git a/tests/test_cadquery.py b/tests/test_cadquery.py index c381f569..83fe9017 100644 --- a/tests/test_cadquery.py +++ b/tests/test_cadquery.py @@ -3157,6 +3157,22 @@ class TestCadQuery(BaseTest): result.faces(">Z").val().Center().toTuple(), (-3, 0, 12), 9 ) + def testWorkplaneOrientationOnVertex(self): + + # create a 10 unit sized cube on the XY plane + parent = Workplane("XY").rect(10.0, 10.0).extrude(10) + + # assert that the direction tuples reflect accordingly + assert parent.plane.xDir.toTuple() == approx((1.0, 0.0, 0.0)) + assert parent.plane.zDir.toTuple() == approx((0.0, 0.0, 1.0)) + + # select the