PDA

View Full Version : Python API - custom MPxNode doesn't execute "compute" method


andrearastelli
11-13-2011, 02:45 PM
Hi guys

here is my code:

import maya.OpenMaya as om
import maya.OpenMayaMPx as ommp
import maya.OpenMayaRender as omr
import maya.OpenMayaUI as omui

MyLocator_ID = om.MTypeId(0x90008)
MyLocator_NAME = "MyLocator"

MyNode_ID = om.MTypeId(0x90009)
MyNode_NAME = "MyNode"

glRenderer = omr.MHardwareRenderer.theRenderer()
glFT = glRenderer.glFunctionTable()

class MyLocator(ommp.MPxLocatorNode):

MyString = om.MObject()

def __init__(self):
ommp.MPxLocatorNode.__init__(self)
p("MyLocator.__init__")

def draw(self, view, path, style, status):
p("MyLocator.draw")

thisNode = self.thisMObject()
plug = om.MPlug(thisNode, self.MyString)
p("input string print test")
p( plug.asString() )

view.beginGL()

glFT.glBegin(omr.MGL_LINES)
glFT.glVertex3f(0.0,0.0,0.0)
glFT.glVertex3f(0.0,5.0,0.0)
glFT.glEnd()

view.endGL()

class MyNode(ommp.MPxNode):

MyString = om.MObject()

def __init__(self):
ommp.MPxNode.__init__(self)
p("MyNode.__init__")

def compute(self, plug, data):
p("MyNode.compute")

stringData = om.MFnStringData()
output = data.outputValue(self.MyString)
output.set( stringData.create("test") )

return om.MStatus.kSuccess

def MyLocator_creator():
p("MyLocator_creator")
return ommp.asMPxPtr(MyLocator())

def MyLocator_initialize():
p("MyLocator_initialize")

tAttr = om.MFnTypedAttribute()
MyLocator.MyString = tAttr.create("MyString", "MyStr", om.MFnData.kString)
MyLocator.addAttribute(MyLocator.MyString)

return om.MStatus.kSuccess

def MyNode_creator():
p("MyNode_creator")
return ommp.asMPxPtr(MyNode())

def MyNode_initialize():
p("MyNode_initialize")

tAttr = om.MFnTypedAttribute()
stringData = om.MFnStringData()
MyNode.MyString = tAttr.create("MyString", "MyStr", om.MFnData.kString, stringData.create("default"))
MyNode.addAttribute(MyNode.MyString)

return om.MStatus.kSuccess

def initializePlugin(mObject):
p("initializePlugin")
mPlugin = ommp.MFnPlugin(mObject)

try:
mPlugin.registerNode(
MyLocator_NAME,
MyLocator_ID,
MyLocator_creator,
MyLocator_initialize,
ommp.MPxNode.kLocatorNode)
p("MyLocator registered")
except:
p("Node not registered", 2)
raise

try:
mPlugin.registerNode(
MyNode_NAME,
MyNode_ID,
MyNode_creator,
MyNode_initialize)
p("MyNode registered")
except:
p("MyNode not registered", 2)
raise

def uninitializePlugin(mObject):
p("uninitializePlugin")
mPlugin = ommp.MFnPlugin(mObject)

try:
mPlugin.deregisterNode(MyLocator_ID)
p("MyLocator deregistered")
except:
p("MyLocator not deregistered",2)
raise

try:
mPlugin.deregisterNode(MyNode_ID)
p("MyNode deregistered")
except:
p("MyNode not deregistered", 2)
raise

def p(text, type=0):
if (type==1):
om.MGlobal.displayWarning(text)
elif (type==2):
om.MGlobal.displayError(text)
else:
om.MGlobal.displayInfo(text)


All seems to work fine, but when i link the two nodes (MyNode --> MyLocator) what happens is that compute method does'nt execute (because nothing is printed).

someone of you know why that happens?

Buexe
11-13-2011, 04:37 PM
prolly because you have not defined a relationship between a input and an output attribute in your initialize mesthod.

andrearastelli
11-13-2011, 05:28 PM
mmh.. and if I haven't any input?

CGTalk Moderation
11-13-2011, 05:28 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.