What Gives with this api 2 thingie?

maya

#1

Why is Maya complaining about this:

 from maya.api.OpenMaya import MTransformationMatrix, MGlobal, MSelectionList, MFnDagNode, MFnTransform

 from maya.api.OpenMaya import MTransformationMatrix, MGlobal, MSelectionList, MFnDagNode, MFnTransform
sel = MGlobal.getActiveSelectionList()  # selection
dagpath = sel.getDependNode(0)          # first node
transform_node  = MFnTransform(dagpath) # MFnTransform
xfm= trans.transformation().asMatrix()  # matrix
new_matrix = some_other_matrix  * xfm                 # maath
new_trans = MTransformationMatrix(new_matrix)
transform_node.setTransformation(new_trans)

This complains

# Error: TypeError: file <maya console> line 8: MTransformationMatrix required. # 

But new_trans clearly is an MTransformationMatrix. What gives? I am testing this on a beta maya – is that it? Does this work for others?


#2

This worked fine for me in 2016. Had to make some minor tweaks though.
Converted trans.tranformation().asMatrix() to transform_node.transformation().asMatrix() and swapped out some_other_matrix for a default MMatrix.

from maya.api.OpenMaya import MTransformationMatrix, MGlobal, MSelectionList, MFnDagNode, MFnTransform, MMatrix
from maya import cmds
cmds.polySphere(name='some_sphere')
cmds.select('some_sphere')

sel = MGlobal.getActiveSelectionList()            # selection
dagpath = sel.getDependNode(0)                    # first node
transform_node  = MFnTransform(dagpath)           # MFnTransform
xfm = transform_node.transformation().asMatrix()  # matrix
new_matrix = MMatrix()  * xfm                     # maath
new_trans = MTransformationMatrix(new_matrix)
transform_node.setTransformation(new_trans)

#3

Also worked fine in 2018 release.


#4

Worked for me on a different machine, too. It’s this cut :frowning: