Added handling of non coplanar faces to BuildSketch

This commit is contained in:
Roger Maitland 2023-03-06 09:13:14 -05:00
parent ee35bfe0b0
commit 2850ac7266
2 changed files with 17 additions and 0 deletions

View file

@ -140,6 +140,14 @@ class BuildSketch(Builder):
new_edges.extend(compound.get_type(Edge))
new_wires.extend(compound.get_type(Wire))
# Align objects with Plane.XY if elevated
for obj in new_faces + new_edges + new_wires:
if obj.position.Z != 0.0:
logger.info("%s realigned to Sketch's Plane", type(obj).__name__)
obj.position = obj.position - Vector(0, 0, obj.position.Z)
if isinstance(obj, Face) and not obj.is_coplanar(Plane.XY):
raise ValueError("Face not coplanar with sketch")
pre_vertices = (
set()
if self.sketch_local is None

View file

@ -117,6 +117,15 @@ class TestBuildOnPlanes(unittest.TestCase):
Rectangle(1, 1)
self.assertTrue(sketch_builder.sketch.faces()[0].is_coplanar(Plane.XZ))
def test_not_coplanar(self):
with self.assertRaises(ValueError):
with BuildSketch() as error:
Add(Face.make_rect(1, 1, Plane.XY.offset(1)))
with self.assertRaises(ValueError):
with BuildSketch() as error:
Add(Face.make_rect(1, 1, Plane.XZ))
class TestBuildSketchExceptions(unittest.TestCase):
"""Test exception handling"""