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?
bob.w
August 1, 2017, 12:01pm
2
Theodox:
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 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)
bob.w
August 1, 2017, 2:00pm
3
Also worked fine in 2018 release.
Worked for me on a different machine, too. It’s this cut