understanding the "translate()" functionality #1185
-
I have here a minimal code: import cadquery as cq
from cadquery import exporters
filename = './rack.stl'
l_rack = 30 # mm [lenght of the rack]
base_x = 10 # mm [base width]
base_y = 10 # mm [base height]
r_x = 0.6
r_y = 0.6
rack = cq.Workplane("XY").box(base_x, base_y, l_rack).\
faces(">Z").workplane().rect(r_x*base_x, r_y*base_y).cutThruAll().\
workplane().translate((0,50,10)).rect(r_x*base_x, r_y*base_x).extrude(10) which produces the figure depicted at the bottom. I tried the following variations without success:
I read the docs and saw examples where the translation happens at the trailing part of the object. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
translate "Returns a copy of all of the items on the stack moved by ..." By calling Here is an example where the box is moved: rack = (
cq.Workplane("XY")
.box(base_x, base_y, l_rack)
.translate((0, 50, 10))
) |
Beta Was this translation helpful? Give feedback.
-
The origin depends on centerOption when creating a workplane on a face. One way to change the origin is to specify it (requires "ProjectedOrigin" centerOption which is the default). result = (
cq.Workplane()
.box(10, 10, 30)
.faces(">Z")
.workplane(origin=(0, 2, 0))
.rect(6, 6)
.extrude(-10, combine="s")
) Or call result = (
cq.Workplane()
.box(10, 10, 30)
.faces(">Z")
.workplane()
.center(0, 2)
.rect(6, 6)
.extrude(-10, combine="s")
) Another way to locate a workplane is covered in the docs example "Locating a Workplane on a vertex". Here locating on an edge: result = (
cq.Workplane()
.box(10, 10, 30)
.faces(">Z")
.edges(">Y")
.workplane(centerOption="CenterOfMass")
.center(0, -3)
.rect(6, 6)
.extrude(-10, combine="s")
) You might have moved the shape in a sketch: s = cq.Sketch().push([(0, 2)]).rect(6, 6)
result = (
cq.Workplane()
.box(10, 10, 30)
.faces(">Z")
.workplane()
.placeSketch(s)
.extrude(-10, combine="s")
) (Note that |
Beta Was this translation helpful? Give feedback.
-
@lorenzncode that's it. thanks! |
Beta Was this translation helpful? Give feedback.
-
We can create the same shape as before using translate (probably not the most straightforward way): result = (
cq.Workplane()
.box(10, 10, 30)
.faces(">Z")
.translate((0, 2, 0))
.wires()
.toPending()
.offset2D(-2)
.extrude(-10, combine="s")
) translate works with any type of shape - a face in this example. |
Beta Was this translation helpful? Give feedback.
The origin depends on centerOption when creating a workplane on a face. One way to change the origin is to specify it (requires "ProjectedOrigin" centerOption which is the default).
Or call
center
:Another way to locate a workplane is covered in the docs example "Locating a Workplane on a vertex". Here locating on an edge: