Glad I found this, I’m heading down a similar route. However I couldn’t get
it working.
There are two problems here I think.
1. Write to any matrix
2. Write to the worldMatrix
Writing to the worldMatrix seems odd; I wouldn’t expect that to affect
anything, and that the attribute is more of a pre-computed value
representing the matrices of itself and all parent nodes. Did you actually
manage to write to that? :O
Writing to *any* matrix however does come in handy, for example if you
create your own matrix attribute, especially via Python API 2.0 (rather
than 1.0 as per your example)
from maya import cmdsfrom maya.api import OpenMaya as om
# Matrix to write
tm = om.MTransformationMatrix()
tm.setTranslation(om.MVector(1, 2, 3), om.MSpace.kObject)
mat = tm.asMatrix()
node = cmds.createNode("transform")
mlist = om.MSelectionList()
mlist.add(node)
mobj = mlist.getDependNode(0)
# Create Attribute
mattr = om.MFnMatrixAttribute()
attr = mattr.create("myMatrix", "mm")
mattr.readable = True
mattr.writable = True
mattr.storable = True
fn = om.MFnDependencyNode(mobj)
fn.addAttribute(attr)
So far so good, we’ve got a vanilla node with a custom matrix attribute.
But now watch as neither API nor cmds is able to actually modify this value.
# Failed edit attempt 1
cmds.setAttr("%s.myMatrix" % node, list(mat), type="matrix")
# Failed edit attempt 2
mplug = fn.findPlug("myMatrix", True)
matrixData = om.MFnMatrixData(mplug.asMObject())
matrixData.set(mat) # Nothing happens
What are we missing here? :O
On Wed, 6 May 2020 at 07:36, Rudi Hammad <[email protected]> wrote:
> never mind, I got.
> I just had to pass te matrix to a MFnMatrixData first and create it.
> Cheers
>
> El domingo, 3 de mayo de 2020, 10:48:00 (UTC-7), Rudi Hammad escribió:
>>
>> Ok, I realized that I had to give the element 0 because it is an array.
>> So with this I don't get any errors now:
>>
>> matList = [18, 24, 7, 0,
>> 54, 17, 1, 0,
>> 22, 34, 8, 0,
>> 11, 78, 6, 1]
>> mScr = OpenMaya.MScriptUtil()
>> MMat = OpenMaya.MMatrix()
>> mScr.createMatrixFromList(matList, MMat)
>>
>>
>> cmds.joint(n="myJoint")
>>
>> mslist = OpenMaya.MSelectionList()
>> mslist.add("myJoint")
>> mobj = OpenMaya.MObject()
>> mslist.getDependNode(0, mobj)
>> mfndepnode = OpenMaya.MFnDependencyNode(mobj)
>>
>> mfndepnode = OpenMaya.MFnDependencyNode(mobj)
>> matPlug = mfndepnode.findPlug("worldMatrix")
>> matPlug_ind0 = matPlug.elementByLogicalIndex(0)
>>
>> mfnMatData = OpenMaya.MFnMatrixData(matPlug_ind0.asMObject())
>>
>> mfnMatData.set(MMat) # No errors, but nothing is happening
>>
>> ..but still, the method .set() is not doing anything. Not sure why...
>>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/4e3be844-fe3c-431d-bd41-3d492ec2ce2d%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/4e3be844-fe3c-431d-bd41-3d492ec2ce2d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCXRf6ERtf6rSc2BtyyARUwxXOWFQYDuNnZofQMncUKpw%40mail.gmail.com.