View Full Version : Python API - problem with compute in custom locator node
andrearastelli 11-11-2011, 09: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..
thanks
(AAARGH!!)
|
|
Azrail
11-11-2011, 09: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.
andrearastelli
11-12-2011, 12: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?
andrearastelli
11-13-2011, 11:18 AM
#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):
p("StringLocatorNode.__init__(self)")
ommp.MPxLocatorNode.__init__(self)
def StringLocatorNodeCreator():
p("StringLocatorNodeCreator")
return ommp.asMPxPtr(StringLocatorNode())
def StringLocatorNodeInit():
p("StringLocatorNodeInit")
return om.MStatus.kSuccess
def initializePlugin(mObj):
obj = ommp.MFnPlugin(mObj)
try:
obj.registerNode(StringLocatorNodeName, StringLocatorNodeID, StringLocatorNodeCreator(), StringLocatorNodeInit(), ommp.MPxNode.kLocatorNode)
p("Successful initialization for StringLocatorNode")
except:
p("Initialization error for StringLocatorNode", 2)
raise
def uninitializePlugin(mObj):
obj = ommp.MFnPlugin(mObj)
try:
obj.deregisterNode(StringLocatorNodeID)
p("Successful uninitialization for StringLocatorNode")
except:
p("Uninitialization error for StringLocatorNode", 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)
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
andrearastelli
11-13-2011, 01:40 PM
ok.. all solved here
CGTalk Moderation
11-13-2011, 01: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.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.