I'm having some trouble accessing the global scale of a transform matrix. Not quite sure why this isn't working...
in the pymel docs, for a transform node, there's two methods; getMatrix, and getTransformation. They both say they return a transformation Matrix - ok great.
When I use getMatrix(worldSpace=1) - it returns the transformation matrix I wanna work with.
But using the getScale method on this gives me errors...
When I use getTransformation().getScale() - I don't get errors, but I also don't get the matrix I wanna work with. what gives? or better yet, how do I access globalScale?
####
import pymel.core as pm
objectMat=pm.selected()[0].getMatrix(worldSpace=1)
print objectMat.getScale("world")
objectTfm=pm.selected()[0].getTransformation()
print objectTfm.getScale("world")
####
Thanks guys!
import pymel.core as pm def returnAncestors(node): """ returns a list of ancstors""" hierarchy = [] while not node.getParent() == None: node = node.getParent() hierarchy.append(node) return hierarchy def retGlobalScale(node): """ returns a cumulative scale from transform hierarchy""" curScale = node.scale.get() for ancestor in returnAncestors(node): scale = ancestor.getScale() curScale = curScale * scale return curScale #EXAMPLE USE OF A TRANSFORM IN A HIERARCHY OF DIFFERENT SCALES scl = retGlobalScale(pm.selected()[0])
Anyhow, I basically just want to return the scale of an object/locator as if you unparented it, and got that value in scale. Which I believe your functions does for me. Thank you. I'm a little surprised maya doesn't give you access to 'global scale', but does for all other components of a transform.
I think this will work great for my need though. Cheers!
There is also the decomposeMatrix node, and the worldMatrix slot of transforms.
my_transform, my_shape = cmds.polyCube()
decompose = cmds.createNode('decomposeMatrix')
cmds.connectAttr(my_transform + ".worldMatrix", decompose + ".inputMatrix")
cmds.getAttr(decompose + ".outputScale")
This will give you the worldspace equivalent of all transform channels in real-time.
cmds.getAttr(decompose + ".outputTranslate")
cmds.getAttr(decompose + ".outputRotate")
cmds.getAttr(decompose + ".outputShear")
...
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9788952a-59f0-4ed7-9311-408ebc12cf4f%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAK85fYnyNmvDh%3DhCXwRnqiHZ%3DPYw0Vxw4_bzPkUyRFrA%40mail.gmail.com.
Anyhow, I basically just want to return the scale of an object/locator as if you unparented it, and got that value in scale. Which I believe your functions does for me. Thank you. I'm a little surprised maya doesn't give you access to 'global scale', but does for all other components of a transform.
The problem is that, in the general case, there's no such thing as a simple "global scale". As soon as you start rotating and applying non-uniform scales, things get messy.
To take an easy example, form a hierarchy where you take a cube, scale in x by 3, rotate 30 degrees, scale in x by 3 again, and rotate 30 degrees again. You now have a transformation that cannot be represented by a single rotation and a single scale. In order to decompose that, you would either need to introduce a shear factor, or allow repeated scales or rotations.
- Paul