Merge pull request #1103 from CadQuery/sketch-vals

Add Sketch val, vals methods
This commit is contained in:
Jeremy Wright
2022-09-21 08:32:26 -04:00
committed by GitHub
2 changed files with 22 additions and 1 deletions

View File

@ -1014,7 +1014,21 @@ class Sketch(object):
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

View File

@ -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():