gumyr / build123d

A python CAD programming library
Apache License 2.0
401 stars 74 forks source link

Expand/Explain examples for mixed mode (Builder and Algebra mode) #514

Open CePeU opened 5 months ago

CePeU commented 5 months ago

Builder Mode - WORKS

length, width, thickness = 80.0, 60.0, 10.0
center_hole_dia = 22.0

with BuildPart() as ex2:
    Box(length, width, thickness)
    Cylinder(radius=center_hole_dia / 2, height=thickness, mode=Mode.SUBTRACT)

Algebra Mode - WORKS

length, width, thickness = 80.0, 60.0, 10.0
center_hole_dia = 22.0

ex2 = Box(length, width, thickness)
ex2 -= Cylinder(center_hole_dia / 2, height=thickness)

MIXED MODE - FAILS

length, width, thickness = 80.0, 60.0, 10.0
center_hole_dia = 22.0

length, width, thickness = 80.0, 60.0, 10.0
center_hole_dia = 22.0

with BuildPart() as ex1:
    Box(length, width, thickness)

with BuildPart() as ex2:
    Cylinder(radius=center_hole_dia / 2, height=thickness)

ex3=ex1-ex2
show_object(ex3)

Explain that you need to use PART

ex3=ex1.part-ex2.part
show_object(ex3)
gumyr commented 5 months ago

To help address this issue commit 338954580ed9b65b5e205e2d27c5bca1c0d10ef3 introduces new error messages to help guide new users:

with BuildPart() as a:
    Box(1, 1, 1)

with BuildPart() as b:
    Cylinder(1, 1)

 c = a + b
RuntimeError: BuildPart is a builder of Shapes and can't be combined. The object being constructed is accessible via the 'part' attribute.

(the same error message applies to '-' and & operators).

Invalid method calls are also handled as shown here:

with BuildSketch() as a:
    Rectangle(1, 1)

a.export_stl("broken.stl")
AttributeError: 'BuildSketch' has no attribute 'export_stl'. Did you intend '<BuildSketch>.sketch.export_stl'?