[Maya-Python] Monitor a Shape Node's Transformations

248 views
Skip to first unread message

Ryan

unread,
May 5, 2010, 12:24:51 PM5/5/10
to python_inside_maya
What's the best way to monitor a shape node's transformations? I'd
like for Maya to call a callback method whenever the world matrix
attribute changes on a specific shape node. I've tried both

addNodeDirtyPlugCallback
addAttributeChangedCallback

from MNodeMessage. But, neither will make calls when the transform
node for the shape node undergoes a transformation.

Thanks,
Ryan

--
http://groups.google.com/group/python_inside_maya

Chad Vernon

unread,
May 5, 2010, 12:37:16 PM5/5/10
to python_in...@googlegroups.com
If you create an array attribute with MFnAttribute::setWorldSpace, then it will get marked dirty when the world transform changes.

Chad
--
http://groups.google.com/group/python_inside_maya

Ryan

unread,
May 6, 2010, 6:02:43 AM5/6/10
to python_inside_maya
Chad,

Thanks for the response.

Will Maya trigger a callback method added with
addNodeDirtyPlugCallback on the shape node after I call the
setWorldSpace func/method on the shape node's '.worldMatrix' attr?

Ryan
--
http://groups.google.com/group/python_inside_maya

Ryan

unread,
May 10, 2010, 11:01:49 AM5/10/10
to python_inside_maya
According to the docs, I should be able to use the
MFnAttribute.setWorldSpace with addNodeDirtyPlugCallback to create a
callback for an attr that gets triggered whenever a change in the
hierarchy that affects the worldSpace transformation happen. But, when
I do this in my command plug-in it does not work! Am I doing something
wrong or is this a BUG?

# A shape node I want to monitor when its worldMatrix attr changes,
which I’ll do by creating
# a worldSpace attr that will get marked dirty when a transformation
is applied above
name = ‘|SpotLight1|SpotLightShape1’

list = OpenMaya.MSelectionList()
list.add(name)
nodeMObj = OpenMaya.MObject()
list.getDependNode(0, nodeMobj)

typedAttrFnSet = OpenMaya.MFnTypedAttribute()
typedAttrObj = typedAttrFnSet.create(’test’, ‘tst’,
OpenMaya.MFnData.kMatrix)
typedAttrFnSet.setCached(0)
typedAttrFnSet.setReadable(1)
typedAttrFnSet.setWritable(0)
typedAttrFnSet.setConnectable(1)
typedAttrFnSet.setHidden(0)
typedAttrFnSet.setArray(1)
typedAttrFnSet.setStorable(0)
typedAttrFnSet.setKeyable(0)
typedAttrFnSet.setWorldSpace(1)
typedAttrFnSet.setUsesArrayDataBuilder(1)
dgModifier = OpenMaya.MDGModifier()
dgModifier.addAttribute(nodeMObj, typedAttrObj,
OpenMaya.MFnDependencyNode.kLocalDynamicAttr)

try:
dgModifier.doIt()
except:
print “doIt failed”

------------------------
# Checking the attr I get

import maya.OpenMaya as OpenMaya
list = OpenMaya.MSelectionList()
list.add(’|rexSpotLight1|rexSpotLightShape1’)
node = OpenMaya.MObject()
list.getDependNode(0, node)
nodeFn = OpenMaya.MFnDependencyNode(node)
attrMObj = nodeFn.attribute(’test’)
attrFn = OpenMaya.MFnTypedAttribute(attrMObj)

print attrFn.isCached()
print attrFn.isReadable()
print attrFn.isWritable()
print attrFn.isConnectable()
print attrFn.isHidden()
print attrFn.isArray()
print attrFn.indexMatters()
print attrFn.isStorable()
print attrFn.isKeyable()
print attrFn.isWorldSpace()
print attrFn.usesArrayDataBuilder()
print attrFn.attrType() == OpenMaya.MFnData.kMatrix

True
True
False
True
False
True
True
False
False
True
True
True

So the attr isArray and isWorldSpace, but is not triggering my
callback method when it is set dirty.. The only thing I can think of
is that this can only be done with static attrs in a node
initialization. But, I didn’t see this in the docs. Is it implied? I
would greatly appreciate your help here. It’s driving me crazy :-(

Ryan Heniser
Double Negative
R&D Software Engineer
Reply all
Reply to author
Forward
0 new messages