Skip to content

Commit cac5cf9

Browse files
Create a child workplane on a vertex (#480)
* 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 <adam-urbanczyk@users.noreply.github.com>
1 parent de2da03 commit cac5cf9

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

cadquery/cq.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,14 @@ def _computeXdir(normal):
543543
if isinstance(obj, Shape)
544544
else obj.Center()
545545
)
546-
normal = self.plane.zDir
547-
xDir = self.plane.xDir
546+
547+
val = self.parent.val() if self.parent else None
548+
if isinstance(val, Face):
549+
normal = val.normalAt(center)
550+
xDir = _computeXdir(normal)
551+
else:
552+
normal = self.plane.zDir
553+
xDir = self.plane.xDir
548554
else:
549555
raise ValueError("Needs a face or a vertex or point on a work plane")
550556

tests/test_cadquery.py

+16
Original file line numberDiff line numberDiff line change
@@ -3157,6 +3157,22 @@ def testWorkplaneFromTagged(self):
31573157
result.faces(">Z").val().Center().toTuple(), (-3, 0, 12), 9
31583158
)
31593159

3160+
def testWorkplaneOrientationOnVertex(self):
3161+
3162+
# create a 10 unit sized cube on the XY plane
3163+
parent = Workplane("XY").rect(10.0, 10.0).extrude(10)
3164+
3165+
# assert that the direction tuples reflect accordingly
3166+
assert parent.plane.xDir.toTuple() == approx((1.0, 0.0, 0.0))
3167+
assert parent.plane.zDir.toTuple() == approx((0.0, 0.0, 1.0))
3168+
3169+
# select the <XZ vertex on the <Y face and create a new workplane.
3170+
child = parent.faces("<Y").vertices("<XZ").workplane()
3171+
3172+
# assert that the direction tuples reflect the new workplane on the <Y face
3173+
assert child.plane.xDir.toTuple() == approx((1.0, 0.0, -0.0))
3174+
assert child.plane.zDir.toTuple() == approx((0.0, -1.0, -0.0))
3175+
31603176
def testTagSelectors(self):
31613177

31623178
result0 = Workplane("XY").box(1, 1, 1).tag("box").sphere(1)

0 commit comments

Comments
 (0)