Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a child workplane on a vertex #480

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cadquery/cq.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,14 @@ def _computeXdir(normal):
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")

Expand Down
16 changes: 16 additions & 0 deletions tests/test_cadquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -3114,6 +3114,22 @@ def testWorkplaneFromTagged(self):
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 <XZ vertex on the <Y face and create a new workplane.
child = parent.faces("<Y").vertices("<XZ").workplane()

# assert that the direction tuples reflect the new workplane on the <Y face
assert child.plane.xDir.toTuple() == approx((1.0, 0.0, -0.0))
assert child.plane.zDir.toTuple() == approx((0.0, -1.0, -0.0))

def testTagSelectors(self):

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