[Closed] How do you find the size of an object?
Hi All
Is there a way to find the size of an objects bounding box in Max script?
I need to find the size of the box in local space rather than world space (I.e. the box is aligned to the axis of the object.)
I hoping theres a simple solution to this. Ive had a look around, but I cant find the answer. :hmm:
Thanks
EDIT: I should have tried first… My recommendation is in world space…
I think what you’re looking for is the .max and .min properties… Those give you the bounding box corners thus “size = a.max – a.min” will give you a point3 with the object’s bounding box dimensions…
Thanks
I guess I could create a temporary clone, rotate it so its aligned in world space. then use the ‘max’ and ‘min’ to find the size before deleting it. :shrug:
I believe that a beter solution is to rotate your object, not make a clone
but in fact you can retrieve the local coordinates of a vertex using ‘coordsys local’ command context.
If you create your own fonction to calculate the bouding box so you will not have to move the object.
I have already write this function for the UVW coordinates… I search …I search…
… and with a little modification:
fn getSize obj =
(
objNumVerts=obj.numVerts
if objNumVerts>0 then
(
coord=coordsys local meshOp.getVert obj 1
minU=coord.x; minV=coord.y; minW=coord.z; maxU=coord.x; maxV=coord.y; maxW=coord.z
for v=2 to objNumVerts do
(
coord=coordsys local meshOp.getVert obj v
if coord.x<minU then minU=coord.x
if coord.y<minV then minV=coord.y
if coord.z<minW then minW=coord.z
if coord.x>maxU then maxU=coord.x
if coord.y>maxV then maxV=coord.y
if coord.z>maxW then maxW=coord.z
)--for
-- min,max,size,center
#([minU,minV,minW],[maxU,maxV,maxW],[maxU-minU,maxV-minV,maxW-minW],[(minU+((maxU-minU)/2.0)),(minV+((maxV-minV)/2.0)),(minW+((maxW-minW)/2.0))])
)
else false
)--fn
obj=selection[1]
format "coordsys LOCAL : getsize obj=%
" (getsize obj)
format "world pos : %
" obj.pos
the array return 4 values: min, max, SIZE, center
sorry it’s only for a MESH ! not for a primitive… but you can translate this for mesh by unsing a temporary edit mesh to read the positions.
offcourse it’s beter to change minU –> minX …
and you can use an another axis than the local axis. See ‘coordsys’ in the helpfile for more details about this.
thanks prettyPixel
Rotating the acutal object will not work for my problem. So comparing all the verts might be the way to do it.
I’m not sure which way to go… I guess it’s time to go home and sleep on it.
thanks guys