MAXScript Frequently Asked Questions
There is currently no access to the Measure Utility from MAXScript, but you can use the following MAXScript function to get the same results:
fn CalculateVolumeAndCenterOfMass obj =
(
Volume= 0.0
Center= [0.0, 0.0, 0.0]
theMesh = snapshotasmesh obj
numFaces = theMesh.numfaces
for i = 1 to numFaces do
(
Face= getFace theMesh i
vert2 = getVert theMesh Face.z
vert1 = getVert theMesh Face.y
vert0 = getVert theMesh Face.x
dV = Dot (Cross (vert1 - vert0) (vert2 - vert0)) vert0
Volume+= dV
Center+= (vert0 + vert1 + vert2) * dV
)
delete theMesh
Volume /= 6
Center /= 24
Center /= Volume
#(Volume,Center)
)
--Call the function on a geometry object - the result will be a list
--containing the Volume and the Center of mass in local space.
theVolAndCom = CalculateVolumeAndCenterOfMass $Sphere01
--To get the world space of the Center of Mass just like in the Utility,
--you have to do some extra work:
theComInWorld = theVolAndCom[2] * $Sphere01.objectTransform
See also