Union and difference
The Builder in itself is adding each element to the other (or subtracting it) according to the parameter choosen for the object created.
1
2
3
4
5
6
7
8
9
10
11
12
13 | from build123d import *
from ocp_vscode import *
set_defaults(reset_camera=Camera.KEEP, black_edges=True,center_grid=True)
with BuildPart() as TestPart:
# Creates a Box
Box(6,5,3)
# Subtracts a cylinder
Cylinder(radius=2,height=4,mode=Mode.SUBTRACT)
# Subtract a Torus
Torus(major_radius=5,minor_radius=2)
show_all()
|
The mode=Mode.ADD is the default that's why it is not needed to write it again.
Now what if we constructed two parts and want them to add together?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 | from build123d import *
from ocp_vscode import *
set_defaults(reset_camera=Camera.KEEP, black_edges=True,center_grid=True)
with BuildPart() as TestPart:
# Creates a Box
Box(6,5,3)
# Subtracts a cylinder
Cylinder(radius=2,height=4,mode=Mode.SUBTRACT)
# Add a Torus
Torus(major_radius=5,minor_radius=2)
with BuildPart() as TestPartII:
# Add a Torus
Torus(major_radius=5,minor_radius=2)
with BuildPart() as AllTogether:
# Add Box
add(TestPart)
# Add Torus
add(TestPartII)
show_object(AllTogether)
|