PDA

View Full Version : python api node, extracting info via MPlug


luizeliasvfx
08-14-2012, 12:06 PM
Hi all!,

I have done a simple node and I want to have as input a rotation
and use MPlug to extract the rotation order from the node that is conneted to this plug.
it is working fine if I connect a scale to the input but if I connect a rotation I got this:
// Error: RuntimeError: (kInvalidParameter): Object is incompatible with this method // :(

here is the code:

import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx

nodeType = "teste"
nodeID = OpenMaya.MTypeId(0x00000003)

class Node(OpenMayaMPx.MPxNode):
rotateOrder = OpenMaya.MObject()
joint = OpenMaya.MObject()
output = OpenMaya.MObject()

def __init__(self):
OpenMayaMPx.MPxNode.__init__(self)

def compute(self,plug, data):
# get joint rotation and rotate order
thisNode = Node.thisMObject(self)
plug = OpenMaya.MPlug(thisNode,Node.joint)
if plug.isConnected():
array = OpenMaya.MPlugArray()
plug.connectedTo(array,1,0)
mobject = array[0].node()
fnTransform = OpenMaya.MFnTransform(mobject)
rotateOrder = fnTransform.rotationOrder()
print "rotate order is: ",rotateOrder

data.setClean( plug )

def creator():
return OpenMayaMPx.asMPxPtr(Node())

def initializer():
nAttr = OpenMaya.MFnNumericAttribute()

# joint input rotation
Node.joint = nAttr.createPoint("jointRotation", "jr")
nAttr.setStorable(True)
nAttr.setWritable(True)
# output
Node.output = nAttr.create("output","out", OpenMaya.MFnNumericData.kFloat, 0.0)
nAttr.setStorable(True)
nAttr.setWritable(True)
# add attributes
Node.addAttribute(Node.joint)
Node.addAttribute(Node.output)

Node.attributeAffects(Node.joint, Node.output)

def initializePlugin(obj):
plugin = OpenMayaMPx.MFnPlugin(obj)
plugin.registerNode( nodeType, nodeID, creator, initializer)

def uninitializePlugin(obj):
plugin = OpenMayaMPx.MFnPlugin(obj)
plugin.deregisterNode(nodeID)

does anybody have a idea why it is not working with rotation? =)

thanks!

CGTalk Moderation
08-14-2012, 12:06 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.