ScriptSpot

Forum topic · General Scripting

How to get the Dimension of an Object like in the Measure Tool?

By pixhellmann · 2012-02-13

Description

/*

Script to create a Plane that fits an selected object from the top view (or the bounding box)

The idea was to use the bounding box information toi create a perfectly matching plane.
the exposeTM was the second idea, but it gives me stranger results than the $.max $.min approach.

create a teapot and rotate it in all 3 axis.

I want the dimensions from the "utilities - measure" tool! how can i access them or calculate them

myself?

*/

-- create a expose Transform node
expT = ExposeTM()

-- set the ExposeNode to the current selection
expT.exposeNode = $

-- get the boundingbox infos from the exposeTM
bb_width = expT.worldBoundingBoxWidth
bb_length = expT.worldBoundingBoxLength

-- get the boundingbox infos from the object itself
bb_max = $.max
bb_min = $.min

-- get the center of the object to position the plane
x_pos = (bb_max.x + bb_min.x) / 2
y_pos =(bb_max.y + bb_min.y) / 2
z_pos = bb_min.z

-- create the plane with length and width same as the bounding box

shadowPlane = Plane length:bb_width width:bb_length pos:[x_pos,y_pos,z_pos] isSelected:off lengthsegs:1 widthsegs:1

-- kill the exposeTM
delete expT

Comments (2)

thanks

pixhellmann · 2012-02-16

puh I spent some hours now and tried to figure out your complex script ^^

the live measure script is awesome! it does exactly measure the values I need!

so I extracted the part where you go through all the vertices of a mesh to find the min/max positions. but it gave me not the exact values.. always a bit more or less than the actual bounding box values.. to complex for me.

i'm just startig to learn maxscript..

but I came up with this solution:

-- create a new free camera with orthogonal projection
c = Freecamera()
c.name = "cam_topBBCam"
c.orthoProjection = true
c.pos = [0,0,300]

-- get the bounding box of the selected object within the coordinate center of the top camera
bb= nodeGetBoundingBox $ c.transform

-- generate the topleft and bottomright points to calculate the width and length between them
bb_min = in coordsys c point pos:bb[1]
bb_max = in coordsys c point pos:bb[2]
-- calculate the length and width between the points
theLength = bb[2].y - bb[1].y
theWidth = bb[2].x - bb[1].x

-- take the minimun point and add the half of the length or width to it to get the middle point of the selected object
x_pos = bb[1].x + (theWidth/2)
y_pos = bb[1].y + (theLength/2)
z_pos = bb_min.transform.pos.z

-- create the plane with length and width same as the bounding box and position it right underneath the object
shadowPlane = Plane length:theLength width:theWidth pos:[x_pos, y_pos, z_pos] isSelected:off lengthsegs:1 widthsegs:1

-- delete all the helper objects
delete c
delete bb_min
delete bb_max

________

and it works!! :) yeai! thanks anyway!
if you have some suggestions how to do it better, please let me know.