XM Magdalena 3D print, GGeorgy (3D)
LC #42 Pipers Alley

View Full Version : Python API - problem with compute in custom locator node

11-11-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-11-2011, 10:01 PM
You can get all the data you need in your draw method via MPlugs:

class SomeNode(OpenMayaMPx.MPxLocatorNode):
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-12-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-13-2011, 12:18 PM
#OpenMaya library
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

#Python library
import json
import math
import sys

StringNodeName = "testStringNode"
StringNodeID = om.MTypeId(0x90030)

StringLocatorNodeName = "testStringLocatorNode"
StringLocatorNodeID = om.MTypeId(0x90040)

class StringLocatorNode(ommp.MPxLocatorNode):

def __init__(self):

def StringLocatorNodeCreator():
return ommp.asMPxPtr(StringLocatorNode())

def StringLocatorNodeInit():
return om.MStatus.kSuccess

def initializePlugin(mObj):
obj = ommp.MFnPlugin(mObj)

obj.registerNode(StringLocatorNodeName, StringLocatorNodeID, StringLocatorNodeCreator(), StringLocatorNodeInit(), ommp.MPxNode.kLocatorNode)
p("Successful initialization for StringLocatorNode")
p("Initialization error for StringLocatorNode", 2)

def uninitializePlugin(mObj):
obj = ommp.MFnPlugin(mObj)

p("Successful uninitialization for StringLocatorNode")
p("Uninitialization error for StringLocatorNode", 2)

def p(text, type=0):
if (type==1):
elif (type==2):

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-13-2011, 02:40 PM
ok.. all solved here

CGTalk Moderation
11-13-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.