Measurements

483 views
Skip to first unread message

Diego Aguilera

unread,
Jun 1, 2022, 9:41:49 PM6/1/22
to CadQuery
Hello,
I'm extruding a single letter using fonts. I need a way to measure from the center to the max X and Y direction.

Jeremy Wright

unread,
Jun 2, 2022, 6:11:04 AM6/2/22
to CadQuery

Ian Geiser

unread,
Jun 3, 2022, 8:41:11 AM6/3/22
to CadQuery
Would this be from the underlying https://dev.opencascade.org/doc/refman/html/class_bnd___box.html methods?  I have a similar interest but it was not clear from the documentation.

Jeremy Wright

unread,
Jun 3, 2022, 9:08:33 AM6/3/22
to CadQuery
Yes, that's what is wrapped in the CadQuery implementation of BoundBox. https://github.com/CadQuery/cadquery/blob/master/cadquery/occ_impl/geom.py#L779

You can use it like this.

import cadquery as cq

text = cq.Workplane().text("C", fontsize=12, distance=2)

bbox = text.val().BoundingBox()

# Use log instead of print if within CQ-editor
print(bbox.center)
print(bbox.DiagonalLength)
# bbox.xmin, bbox.xmax and so on are also available

Ian Geiser

unread,
Jun 3, 2022, 1:54:01 PM6/3/22
to CadQuery
Nice!  It's hard to tell what is provided by the underlying binding.  Is that documented somewhere?

Jeremy Wright

unread,
Jun 3, 2022, 2:08:47 PM6/3/22
to Ian Geiser, CadQuery
I don't think we have documentation on OCP anywhere, but the following file gives a listing of what's exposed from OCCT in OCP. The OCCT documentation should apply for the most part.


--
cadquery home: https://github.com/CadQuery/cadquery
post issues at https://github.com/CadQuery/cadquery/issues
run it at home at : https://github.com/CadQuery/CQ-editor
---
You received this message because you are subscribed to the Google Groups "CadQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cadquery+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cadquery/fd1de936-3cf5-4fb3-9e72-2575e773c914n%40googlegroups.com.

Diego Aguilera

unread,
Jun 6, 2022, 10:37:47 PM6/6/22
to CadQuery
Thanks for the reply. Unfortunately the fonts don't appear to be centered along the X axis. I've tried a could different fonts. Getting xmax works fine for one half, but not the other. See attached image.

Does the BoundingBox return -xmax and +xmax? Or can I limit the BoundingBox to get just the left or right side?

Screen Shot 2022-06-06 at 10.33.39 PM.png

Jeremy Wright

unread,
Jun 8, 2022, 7:00:26 AM6/8/22
to Diego Aguilera, CadQuery
xmin and xmax are maybe relative to the workplane center instead of the center of the font. I used the center of the bounding box to offset itself, and got much better results.

import cadquery as cq

text = cq.Workplane().text("X", 12, 1, False, True)

# Show the bounding box
bbox = text.val().BoundingBox()
# cen = text.val().CenterOfBoundBox() # Alternative method of getting the center.
bb = cq.Workplane().moveTo(bbox.center.x, bbox.center.y).rect(bbox.xmax-bbox.xmin, bbox.ymax-bbox.ymin).extrude(1)

show_object(text)
debug(bb)


x_letter.png

Diego Aguilera

unread,
Jun 8, 2022, 1:19:09 PM6/8/22
to CadQuery
Thank you Jeremy. That's working wonderfully.

Diego Aguilera

unread,
Jun 18, 2022, 10:38:41 AM6/18/22
to CadQuery
I"m having trouble with the Bounding Box again. I'm now selecting the Y Face of the 'block'. I want to create a rectangle (eventually text) centered on the T Face.


The Bounding Box worked well on the previous function (addWeepingHole). I was able to get the Y center, but the X center was way off.

Roger Maitland

unread,
Jun 18, 2022, 2:10:51 PM6/18/22
to Diego Aguilera, CadQuery
If I add the following to your addVersion method:
print(f"{yFacebbox.xmin=},{yFacebbox.xmax=}")
print(f"{yFacebbox.ymin=},{yFacebbox.ymax=}")
print(f"{yFacebbox.zmin=},{yFacebbox.zmax=}")
and get:
yFacebbox.xmin=-7.1679818708333345,yFacebbox.xmax=8.847981870833333
yFacebbox.ymin=10.206007590429687,yFacebbox.ymax=10.20600779042969
yFacebbox.zmin=-21.3200001,yFacebbox.zmax=1.0000001
(note the y values are the same)
but the center.y is used to position a rectangle with:
.moveTo(yFacebbox.center.x, yFacebbox.center.y)
Are you working with the plane you intend to be working with?

Diego Aguilera

unread,
Jun 19, 2022, 12:12:10 PM6/19/22
to Roger Maitland, CadQuery
Hello Roger,
I believe I am. In general, I draw a letter on the Z face, put a BoundBox around it, and extrude a cube down. 

On the function addWeeping hole I follow the same process to create a hole on the X face.

How can I tell if I’m working on the correct face? Is there a way to highlight it?

Jeremy Wright

unread,
Jun 19, 2022, 2:20:16 PM6/19/22
to Diego Aguilera, Roger Maitland, CadQuery
I'm CQ-editor I normally do something like this to highlight a selected face.

face = box.faces(">Z")
debug(face)

You received this message because you are subscribed to a topic in the Google Groups "CadQuery" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cadquery/_Fat2pxDEMc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cadquery+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cadquery/17C5AAFB-5FDF-4D77-8240-F285874398E9%40aguilera.me.

Diego Aguilera

unread,
Jun 19, 2022, 3:20:14 PM6/19/22
to Jeremy Wright, Roger Maitland, CadQuery
Thanks Jermey. I forgot about the debug.

I am on the correct Face. You can see on the image before the rectangle I’m extruding is off in left field.

Is it necessary to create a Workplane once I select the Y Face? It doesn’t seem to make a difference.

Roger Maitland

unread,
Jun 19, 2022, 6:56:04 PM6/19/22
to Diego Aguilera, Jeremy Wright, CadQuery

Diego Aguilera

unread,
Jun 19, 2022, 9:29:39 PM6/19/22
to Roger Maitland, Jeremy Wright, CadQuery
No, I don’t think so. Tried it anyways. It didn’t center it.

On Jun 19, 2022, at 6:55 PM, Roger Maitland <gum...@gmail.com> wrote:

On Sun, Jun 19, 2022 at 3:20 PM Diego Aguilera <die...@aguilera.me> wrote:
Thanks Jermey. I forgot about the debug.

I am on the correct Face. You can see on the image before the rectangle I’m extruding is off in left field.

Is it necessary to create a Workplane once I select the Y Face? It doesn’t seem to make a difference.

<PastedGraphic-1.png>

Diego Aguilera

unread,
Jun 20, 2022, 2:01:30 PM6/20/22
to CadQuery
I've simplified the code to better illustrate the issue. I expected the box to be created on the center of the Y Face. Yet, it's created much higher than expected.

Keep in mind, I'm using the Bound Box on the Y Face because on the 'real' code, this changes dynamically with the character and font. It's not a simple rectangle.

Code:
length = 3.0
height = 7.0
thickness = 7.0
center_hole_dia = 2.0

# Create a box based on the dimensions above and add a 22mm center hole
result = cq.Workplane("XY").box(length, height, thickness)

bbox = result.faces(">Y").val().BoundingBox()
debug(result.faces(">Y"))

print(' ')
print( 'X: ', bbox.center.x) #0.0
print( 'Y: ', bbox.center.y) #3.5
print( 'Z: ', bbox.center.z) #0.0

result = result.faces(">Z").workplane().hole(center_hole_dia)

result = result.faces(">Y").workplane()\
    .moveTo(bbox.center.x, bbox.center.y).box(1,1,1)
   
show_object(result)
Screen Shot 2022-06-20 at 2.00.45 PM.png

Roger Maitland

unread,
Jun 20, 2022, 4:13:36 PM6/20/22
to Diego Aguilera, CadQuery
Try the 'CenterOfMass' option like this:
result = result.faces(">Y").workplane(centerOption="CenterOfMass").box(1, 1, 1)
which results in:
image.png

Diego Aguilera

unread,
Jun 22, 2022, 9:47:37 PM6/22/22
to CadQuery

Roger/Jermey,
Thank you both so much. I believe it's working as expected. 

For my reference, when I change faces as shown in the last example, where is the new starting point (0,0)?

Roger Maitland

unread,
Jun 27, 2022, 4:32:03 PM6/27/22
to CadQuery
There are three options:
centerOption: Literal["CenterOfMass", "ProjectedOrigin", "CenterOfBoundBox"] = "ProjectedOrigin",

ProjectedOrigin depends on the operations that preceded the new workplane so it can be a bit confusing to know in advance where it will be. 
Reply all
Reply to author
Forward
0 new messages