Go through workplane documentation and explain it's concepts.
Create a 2d workplane on the XY axis with one point starting at 0,0,0
result = cq.Workplane("XY")
Let's append a sphere at the center point
result = cq.Workplane("XY")
result = result.sphere(1)
The circle is placed centered relative to the initial point at 0,0,0.
If we move where the center point on the workplane resides the circle will be placed at the new destination.
result = cq.Workplane("XY").center(3,3)
result = result.sphere(1)
By default a workplane has one point on the stack, and all operations are applied against that point.
To prove that out let's add a box to the workplane.
result = cq.Workplane("XY").center(3,2)
result = result.sphere(1).box(1,1,2.5)
Because the workplane is in relative dimensions if we change initial axis and the created solids are rotated from our perspective but really the workplane has now shifted.
result = cq.Workplane("XZ").center(3,2)
result = result.sphere(1).box(1,1,2.5)
Notice that we are calling box off of sphere?
This is chaining
we could also rewrite our code look like this.
result = cq.Workplane("YZ").center(3,2).sphere(1).box(1,1,2.5)
OR
result = (
cq.Workplane("YZ")
.center(3,2)
.sphere(1)
.box(1,1,2.5)
)
Lets move the box independent of the sphere.
result = (
cq.Workplane("YZ")
.center(3,2)
.sphere(1)
.workplane(offset=2)
.box(1,1,2.5)
)
calling workplane off of the sphere; makes a new copy of the existing workplane and sets the original workplane as the new workplane's parent.
We then offset the new workplanes origin point height by 2mm on the z axis which is being tranlated to the y axis in the final output.
- Move back to the XY axis on the initial workplane
- Lets add a third workplane with a box
result = (
cq.Workplane("XY")
.center(3,2)
.sphere(1)
.workplane(offset=2)
.box(1,1,2.5)
.workplane(offset=4.5)
.box(2,2,2.5)
)
result = (
cq.Workplane("XY")
.center(3,2)
.sphere(1)
.workplane(offset=2)
.box(1,1,2.5).tag("center")
.box(1,1,2.5)
.workplane(offset=4.5)
.box(2,2,2.5)
.workplaneFromTagged("center")
.box(1,5,1)
)
The return from the last box operation in the chain is the center tagged workplane, and to prove that lets move the origin point on the center plane and add another box.
result = (
cq.Workplane("XY")
.center(3,2)
.sphere(1)
.workplane(offset=2)
.box(1,1,2.5).tag("center")
.workplane(offset=4.5)
.box(2,2,2.5)
.workplaneFromTagged("center")
.box(1,5,1)
.center(5,5)
.box(5,1,1)
)
You can traverse up and down the stack relative to any child on the stack.
Stack Methods