[Solved] Measuring wrong BoundingBox

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Torxal
Posts: 11
Joined: Wed May 11, 2022 8:51 pm

[Solved] Measuring wrong BoundingBox

Post by Torxal »

STEP File from: https://grabcad.com/library/marine-prop ... r-mixers-1

Hey Guys,

i want to measure the diameter of a propeller over the python interpreter. Because i dont have a reference point for the propeller tips, i cant measure the diameter directly with the measuring Tool of the Part Module. So my idea was to calculate the length of the BoundaryBox of the propeller for a rotation of 120 degrees in discreet angles. The maximum length i get should help calculating the approximated diameter.

But i get into a problem:

First of all i activate the boundary box of the imported step over

Code: Select all

propeller = FreeCADGui.getDocument(".....").getObject("....")
propeller.BoundaryBox = 1
Now i see:
F2CB4848-9937-48ED-AC62-CC3C1E77FB23.jpeg
F2CB4848-9937-48ED-AC62-CC3C1E77FB23.jpeg (38.32 KiB) Viewed 1076 times
Now i want to get the length information from the boundarybox and i go with:

Code: Select all

PropellerDiameter = FreeCADGui.getDocument("...").getObject("..").getBoundingBox().YLength
PropellerDiameter = FreeCADGui.getDocument("...").getObject("..").getBoundingBox().ZLength
Instead of getting the correct 178 mm diameter i get 244 mm. It seems to be a problem with selecting the wrong boundarybox. I can type into the python interpreter the command:

Code: Select all

 Gui.runCommand('Std_SelBoundingBox',1)
and i see another boundarybox (green). It although dependends on the rotation of the propeller.
7521975A-86F2-42FE-8FFE-2C188FFB460A.jpeg
7521975A-86F2-42FE-8FFE-2C188FFB460A.jpeg (42.96 KiB) Viewed 1076 times
It looks like i get the length of the green boundary box. What do i do wrong? I would be very grateful for any help :) .
Last edited by Torxal on Mon May 23, 2022 3:42 pm, edited 2 times in total.
chrisb
Veteran
Posts: 53945
Joined: Tue Mar 17, 2015 9:14 am

Re: Measuring wrong BoundingBox

Post by chrisb »

For the XLength of the bounding box of an object "obj" I use

Code: Select all

obj.Shape.BoundBox.XLength
Alas, this will not give you the double radius.

But if the center of the propeller is at (0,0,0) and one wing is pointing towards X, you get the radius as

Code: Select all

obj.Shape.BoundBox.XMax
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Torxal
Posts: 11
Joined: Wed May 11, 2022 8:51 pm

Re: Measuring wrong BoundingBox

Post by Torxal »

Hey @chrisb,

big thanks to your answer 8-) . I tried youre code and it works for me perfektly. Thanks :)! Just for the better understanding. Is there a reason why the green marked BoundingBox differs from the white BoundingBox?

For the documentation:

I changed
FreeCADGui.getDocument("...").getObject("..").getBoundingBox().XLength
to
FreeCADGui.getDocument("...").getObject("..").Objekt.Shape.BoundBox.XLength
chrisb
Veteran
Posts: 53945
Joined: Tue Mar 17, 2015 9:14 am

Re: Measuring wrong BoundingBox

Post by chrisb »

Torxal wrote: Sun May 15, 2022 10:15 am Is there a reason why the green marked BoundingBox differs from the white BoundingBox?
I don't know, my Python knowledge is very limited.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
naxq0
Posts: 51
Joined: Wed Apr 25, 2018 7:45 am

Re: Measuring wrong BoundingBox

Post by naxq0 »

I posted on an older post about the bounding box accuracy that might be interesting to you:
https://forum.freecadweb.org/viewtopic.php?f=22&t=38402
naxq0 wrote: Thu Aug 08, 2019 11:40 am
Chris_G wrote: Thu Aug 08, 2019 10:37 am I think the Bounding Box is computed from the tessellation of the shape :
Yep. Whenever you're interested in an accurate bound box, you should always tessellate beforehand.

In fact, I think the accuracy of other operations also depends on whether or not you've tessellated the part. Not sure exactly which ones now, but I'm pretty certain I've run into this issue before... might have been distToShape?
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Measuring wrong BoundingBox

Post by wmayer »

Torxal
Posts: 11
Joined: Wed May 11, 2022 8:51 pm

Re: [Solved] Measuring wrong BoundingBox

Post by Torxal »

@wmayer , @naxq0 thanks for sharing these informations :D !
Post Reply