View Full Version : Python API - problem with compute in custom locator node
11 November 2011, 10:59 AM
I'm using maya 2012 and I have this simple question:
why maya crashes when i implement the compute metod in my custom locator?
In draw all works fine, but when I write something incompute (even: om.Mglobal.displayInfo("test") ) everything crash..
so.. because i can't solve this problem by myself.. if one of you know how i can input a string in my locator from another node (MPxNode) using draw i really appreciate it..
11 November 2011, 10:01 PM
You can get all the data you need in your draw method via MPlugs:
annText = OpenMaya.MObject()
def draw(self, view, path, style, status):
thisNode = self.thisMObject()
# Annotation Attributes:
txtPlug = OpenMaya.MPlug(thisNode, self.annText)
txtString = txtPlug.asString()
But be warned that this is executed on every refresh (think FPS here), so it's not useful for some heavier work.
About the crashes - I've some locators with compute and they're working fine, but if you're on Windows Maya is very picky about scripted plugs, and sometimes even crashes on syntax/indentation errors, so check your code carefully.
11 November 2011, 01:21 PM
thanks a lot for your help
now.. i've some questions about how attributes works in maya nodes.
let me explain.. i have an MPxNode that in compute metod should assign to an attribute some string (for example a JSON string).
When i connect, in maya hypershade, my first node with my locator trough this string in/out attribute.. what happens is that in the locator the string is empty (or, in some cases the type is not a string but a number.. and i can't figure it out why)
how should i send out, from MPxNode the string correctly?
11 November 2011, 12:18 PM
import maya.OpenMaya as om
import maya.OpenMayaMPx as ommp
import maya.OpenMayaRender as omr
import maya.OpenMayaUI as omui
#Maya commands library
import maya.cmds as cmds
StringNodeName = "testStringNode"
StringNodeID = om.MTypeId(0x90030)
StringLocatorNodeName = "testStringLocatorNode"
StringLocatorNodeID = om.MTypeId(0x90040)
obj = ommp.MFnPlugin(mObj)
obj.registerNode(StringLocatorNodeName, StringLocatorNodeID, StringLocatorNodeCreator(), StringLocatorNodeInit(), ommp.MPxNode.kLocatorNode)
p("Successful initialization for StringLocatorNode")
p("Initialization error for StringLocatorNode", 2)
obj = ommp.MFnPlugin(mObj)
p("Successful uninitialization for StringLocatorNode")
p("Uninitialization error for StringLocatorNode", 2)
def p(text, type=0):
someone can tell my why i can't create the StringLocatorNode?
This is a code test I have made 10 minutes ago.. and something is missing but i can't understand what :s
11 November 2011, 02:40 PM
ok.. all solved here
11 November 2011, 02:41 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.