Skip to content

Commit

Permalink
Merge pull request #1103 from CadQuery/sketch-vals
Browse files Browse the repository at this point in the history
Add Sketch val, vals methods
  • Loading branch information
jmwright authored Sep 21, 2022
2 parents b7dad5e + 6438737 commit 259cc7b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cadquery/sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,21 @@ def located(self: T, loc: Location) -> T:

def finalize(self) -> Any:
"""
Finish sketch construction and return the parent
Finish sketch construction and return the parent.
"""

return self.parent

def val(self: T) -> SketchVal:
"""
Return the first selected item or Location().
"""

return self._selection[0] if self._selection else Location()

def vals(self: T) -> List[SketchVal]:
"""
Return the list of selected items.
"""

return self._selection
7 changes: 7 additions & 0 deletions tests/test_sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ def test_selectors():
s.reset().wires(LengthNthSelector(1))

assert len(s._selection) == 2
assert len(s.vals()) == 2

s.reset().vertices("<X and <Y").val()
assert s.val().toTuple() == approx((-2.5, -0.5, 0.0))

s.reset().vertices(">>X[1] and <Y").val()
assert s.val().toTuple()[0] == approx((0, 0, 0))


def test_edge_interface():
Expand Down

0 comments on commit 259cc7b

Please sign in to comment.