diff --git a/src/build123d/build_common.py b/src/build123d/build_common.py index 0c7dfbd4..1e942bfb 100644 --- a/src/build123d/build_common.py +++ b/src/build123d/build_common.py @@ -204,7 +204,8 @@ def __init__( mode: Mode = Mode.ADD, ): self.mode = mode - self.workplanes = WorkplaneList._convert_to_planes(workplanes) + planes = WorkplaneList._convert_to_planes(workplanes) + self.workplanes = planes if planes else [Plane.XY] self._reset_tok = None current_frame = inspect.currentframe() assert current_frame is not None @@ -234,7 +235,6 @@ def __enter__(self): self.builder_parent = Builder._get_context() else: self.builder_parent = None - self.workplanes = self.workplanes if self.workplanes else [Plane.XY] self._reset_tok = self._current.set(self) diff --git a/tests/test_build_common.py b/tests/test_build_common.py index ef3eb331..3a9b170e 100644 --- a/tests/test_build_common.py +++ b/tests/test_build_common.py @@ -194,6 +194,19 @@ def test_multiple(self): Line((0, 0), (0, 1)) self.assertEqual(len(test.pending_edges), 2) + def test_workplane_popping(self): + # If BuildSketch pushes and pops its workplanes correctly, the order shouldn't matter + with BuildPart(Plane.XZ) as a: + with BuildSketch(): + Circle(1) + Cylinder(1, 5) + + with BuildPart(Plane.XZ) as b: + Cylinder(1, 5) + with BuildSketch(): + Circle(1) + self.assertAlmostEqual(a.part.volume, (a.part & b.part).volume, 4) + class TestCommonOperations(unittest.TestCase): """Test custom operators"""