Selecting faces of a cube #1798
Replies: 4 comments 8 replies
-
I ended up creating a cube with labels as an example - hope it might be useful. from cadquery.func import *
from cadquery.vis import show
d = 30
dcut = 0.8
htext = 6
def make_text(s):
return extrude(text(s, htext, "RobotoMono Nerd Font"), (0, 0, dcut)).move(
z=d / 2.0 - dcut
)
res = box(d, d, d).move(z=-d / 2.0) # move to center box in z
res = res - make_text("TOP")
res = res - make_text("BOTTOM").move(rx=180)
res = res - make_text("RIGHT").move(ry=90).move(rx=90)
res = res - make_text("FRONT").move(rx=90)
res = res - make_text("LEFT").move(ry=-90).move(rx=90)
res = res - make_text("BACK").move(rx=-90).move(ry=180)
res.export("cube.stl")
show(res, width=500, height=500, xpos=0.3) |
Beta Was this translation helpful? Give feedback.
-
@lorenzncode, txs for the help on this! Now I have a related question, rather than recessed text I wanted to see how protruding text would work and look. With the help of ChatGPT I found away, basically creating the text on the default XY plane and then translate it to >Z manually. It works but I wanted to do the work using a workplane on the >Z face, which seems more natural and the purpose of a workplane. Here is the code with the two versions controlled by the if statement and you can see the error.
|
Beta Was this translation helpful? Give feedback.
-
Hi @winksaville, See the following. #!/usr/bin/env python3
import cadquery as cq
from cadquery.vis import show
d = 30 # cube size
htext = 6 # text height
hextrude = 0.3 # extrusion height
# Create base cube
box = cq.Workplane("XY").box(d, d, d)
# show(box) # Show the cube
# Create a workplane on the face I want to have the text appear
wp = box.faces(">Z").workplane()
# show(wp) # Show the empty workplane
# Note cut=True by default, setting cut to False here
# Create 3D text, combine with cube: "a" for additive or True for same result
res = wp.text("TOP", htext, hextrude, False, "a", font="RobotoMono Nerd Font")
show(res)
# or create 3D text without combine; combine=False by default
text_3d = wp.text("TOP", htext, hextrude, False, font="RobotoMono Nerd Font")
show(text_3d)
res2 = box.union(text_3d) # Combine the cube and text
show(res2) |
Beta Was this translation helpful? Give feedback.
-
@lorenzncode , thank you I now have a better understanding. Personally, this is seems more complicated than is necessary, my feeling there should be a
With those changes recessed is:
protruding is:
There is the code I used to educate myself from this
|
Beta Was this translation helpful? Give feedback.
-
I want to do something fairly simple, I want to create a cube and select a face and then select the corresponding back face and add some text so that I can easily label multiple cubes with different information. I'm going to be 3D printing these cubes and later more sophisticated things.
Suggestions on how I might go about that?
Beta Was this translation helpful? Give feedback.
All reactions