Maya Python MNodeMessage sample
- February 28th, 2012
- Posted in Maya Python
- Write comment
This is a simple example of the MNodeMessage usage.
import maya.cmds as cmds
import maya.OpenMaya as om
#Ref http://pastebin.com/mntSGhex
cmds.polySphere()
cmds.select('polySphere1')
def changed_radius( msg, mplug, otherMplug, clientData):
nodeName, attrName = mplug.name().split('.')
#if msg & om.MNodeMessage.kAttributeSet:
if msg == 2056:
if nodeName == 'polySphere1':
if attrName == 'radius':
print "Radius Changed"
rd = cmds.getAttr('polySphere1.radius')
cmds.setAttr('polySphere1.subdivisionsAxis', rd*3)
def getNode():
#Get the node as MObject and set the id message
MSelectionList = om.MSelectionList()
om.MGlobal.getActiveSelectionList(MSelectionList)
node = om.MObject()
MSelectionList.getDependNode(0, node)
clientData = None
id = om.MNodeMessage.addAttributeChangedCallback(node, changed_radius,clientData)
getNode()
