Tuesday, August 17, 2010

Select object less than X size

This is well discussed tip where MAXScript assistance is necessary, but I see so it still appear as question into the forums. Well, how to select all objects smaller than some certain volume size? Into the MAXScript Reference has a good example function to measure the object volume. The example function in the help return the volume and center of mass, so I was lightly modify it to return only the volume size.
fn CalculateVolume obj = 
local Volume= 0.0
local Center= [0.0, 0.0, 0.0]
local theMesh = snapshotasmesh obj
local numFaces = theMesh.numfaces
for i = 1 to numFaces do
local Face= getFace theMesh i
local vert2 = getVert theMesh Face.z
local vert1 = getVert theMesh Face.y
local vert0 = getVert theMesh Face.x
local dV = Dot (Cross (vert1 - vert0) (vert2 - vert0)) vert0
Volume+= dV
delete theMesh
Volume /= 6
Next, will made another function that to select the objects...
fn selectObjByVolume volLimit = 
select (
for obj in geometry where \
CalculateVolume obj <= volLimit collect obj
... and here is the example usage:
selectObjByVolume 337


No comments:

Post a Comment

Thanks for your comment