View Full Version : How to find true scale of object using MEL?
modelriglightcomp 02232011, 11:46 PM Hi
Does anyone know how one might ascertain the true/global scale of an object using MEL  that is, the scale of the object taking into consideration the scale values of all the parent nodes?
Thanks!


ruchitinfushion
02242011, 05:37 AM
I think Real Scale Value = Bounding Box Max * 2.
*Take polyCube(Scale 1,1,1)
*Set scale to (5,5,5)
*Freeze the transformations(Scale value become 1,1,1 & Bounding Box Max = 2.5). Not sure but try out & see.All the best
Robert Bateman
02242011, 09:52 AM
xform q ws s "joint1"
BigRoyNL
03022011, 11:03 PM
The following is actually calculating the 'size' of the bounding box.
ruchitinfushion was wrong that multiplying the max of the boundingBox by 2 would give you the size of the object. That would only work if the center of the object would be precisely on the center of your grid. The following should work in all conditions:
float $boundingBox[] = `xform q bb "pCube1"`;
$xSize = $boundingBox[3]$boundingBox[0]; // xmax  xmin
$ySize = $boundingBox[4]$boundingBox[1]; // ymax  ymin
$zSize = $boundingBox[5]$boundingBox[2]; // zmax  zmin
As Robert Bateman stated:
xform q ws s "pCube1"
That will give you the scale in world space, so it takes in considerations all of it's parent transform nodes and gives the actual result of this all.
ruchitinfushion
11242011, 03:50 PM
To get actual size i tried lots of expression but in some case it fails to work.
Here is the way i tried to check Obj Size
Step 1:
volume = 'pCylinder1'
volumeShape = mc.listRelatives(volume, s=True)
volumeBox = mc.exactWorldBoundingBox(volumeShape)
xSize = math.ceil(((abs(volumeBox[0])) + (abs(volumeBox[3]))))
ySize = math.ceil(((abs(volumeBox[1])) + (abs(volumeBox[4]))))
zSize = math.ceil(((abs(volumeBox[2])) + (abs(volumeBox[5]))))
Step 2:
volume = 'pCylinder1'
volumeShape = mc.listRelatives(volume, s=True)
BBOXminX = mc.getAttr(volumeShape[0] + '.boundingBoxMinX')
BBOXminY = mc.getAttr(volumeShape[0] + '.boundingBoxMinY')
BBOXminZ = mc.getAttr(volumeShape[0] + '.boundingBoxMinZ')
BBOXmaxX = mc.getAttr(volumeShape[0] + '.boundingBoxMaxX')
BBOXmaxY = mc.getAttr(volumeShape[0] + '.boundingBoxMaxY')
BBOXmaxZ = mc.getAttr(volumeShape[0] + '.boundingBoxMaxZ')
xSize = math.ceil(((abs(BBOXminX)) + (abs(BBOXmaxX))) * sizeMult)
ySize = math.ceil(((abs(BBOXminY)) + (abs(BBOXmaxY))) * sizeMult)
zSize = math.ceil(((abs(BBOXminZ)) + (abs(BBOXmaxZ))) * sizeMult)
The problem here is,sometimes when i try to set scale of other objects with above xSize,ySize,zSize.
it gives big number and also make changes in bounding box of mesh shape node(query node).Why????
CGTalk Moderation
11242011, 03:50 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©20002014, Jelsoft Enterprises Ltd.