PDA

View Full Version : Referring to attr values inside node class


VesuvianPrime
03-08-2011, 06:18 PM
Hi

I'm currently trying to print the value of an attribute during compute:
loc = dataBlock.inputValue(ADANode.location).asString()
print loc
But I'm getting some weird hex stuff being printed to the console:
_20d33424_p_MString
_b0df3424_p_MString
_80526a24_p_MString

How do I get the value of the attribute in a form I can use? is there a way I can convert the output?


Furthermore, within the node class init I am simply declaring:
self.tloc = ""
But when I try to concatenate I get:
TypeError: print ( "Old location: " + self.tloc): cannot concatenate 'str' and 'PySwigObject' objects

This really confuses me. Is Maya doing something to my datatypes that I don't want it to? How can I fix this?

Thanks

NaughtyNathan
03-08-2011, 10:46 PM
when you create instances of an object, printing the object just prints the objects memory address. (I think that's what that hex is anyway :) )

those hex address you've shown tell you the object type is an MString object, so to print the "value" of it, you need to access the method or attribute of that object (or use another class) that prints or stores the value, but I'm not that familiar with the API classes, so you'd have to check the API docs for MString. (or wait for someone else to answer! :D )

:nathaN

VesuvianPrime
03-08-2011, 11:26 PM
After a lot of searching I found an old forum post with the answer. Solution was to do this:

dataHandle = dataBlock.inputValue( ADANode.location )
data = dataHandle.data()
loc = om.MFnStringData(data).string()

CGTalk Moderation
03-08-2011, 11:26 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.