Make a message attribute without a warning

578 views
Skip to first unread message

barnabas79

unread,
Sep 30, 2008, 12:41:23 PM9/30/08
to python_inside_maya
Hey all - I was wondering if there was a way to add a dynamic message
attribute without receiving a warning - ie, if I do:

import maya.cmds as cmds
cmds.addAttr(longName="msgAttr", attributeType="message")

... I receive:

// Warning: file: C:/3D/Maya2008/scripts/AETemplates/
AEreplaceCompound.mel line 97: Message attributes have no data
values. //

Anyone know a way to get around this, ie add a message attribute
without receiving an error? Or some way to temporarily disable the
error?

I know I could do this from the API, but then I would lose the ability
to undo, which I'd rather be able to keep.

barnabas79

unread,
Sep 30, 2008, 1:26:40 PM9/30/08
to python_inside_maya
Ok, quick follow up:

First of all, this error only seems to occur if you have added a
dynamic compound attribute, and then looked at it in the attribute
editor.

Ie, if you execute this (taken straight from the maya docs):

http://pastebin.com/m2c019dfe

cmds.sphere( name='earth' )
cmds.addAttr( longName='sampson', numberOfChildren=5,
attributeType='compound' )
cmds.addAttr( longName='homeboy', attributeType='matrix',
parent='sampson' )
cmds.addAttr( longName='midge', attributeType='message',
parent='sampson' )
cmds.addAttr( longName='damien', attributeType='double',
parent='sampson' )
cmds.addAttr( longName='elizabeth', attributeType='double',
parent='sampson' )
cmds.addAttr( longName='sweetpea', attributeType='double',
parent='sampson' )

...then open up the attribute editor, and look at your pretty new
compound attribute (side note - 'homeboy' is displayed as 'sampson'.
Odd...), and THEN do:

cmds.addAttr(longName="msgAttr", attributeType="message")

...you'll get the annoying warning.

The second point is that I found a way around the warning, though it's
a huge hack - basically, just temporarily rebind AEreplaceCompound.
So, a function such as:

http://pastebin.com/m2a0ce632

def addMsgAttrNoWarning(node, attr, *args, **kwargs):
import maya.mel as mel
import maya.cmds as cmds

mel.eval(r'''
global proc AEreplaceCompound ( string $controlName, string $plugName,
string $changedCommand )
{
evalDeferred("source AEreplaceCompound");
}
''')
cmds.addAttr(node, longName=attr, attributeType="message",
*args, **kwargs)


... will avoid the warning. But it seems like such a potentially
messy solution, I think I'd rather just change my script to not use
compound attributes (they're not as useful as I'd hoped, anyway), and
hope the user doesn't add any themselves either.

- Paul

Justin Leach

unread,
Sep 30, 2008, 12:50:35 PM9/30/08
to python_in...@googlegroups.com
Give this a try:

import maya.cmds as cmds
msg_node = cmds.group(empty=True,name='messageNode')
cmds.addAttr(msg_node,attributeType='message',longName='myMessage')

Perhaps its breaking because you dont have an object specified as the
first argument, although it should be using your selection.

Dean Edmonds

unread,
Oct 5, 2008, 11:37:57 PM10/5/08
to python_in...@googlegroups.com
In your addAttr command add the following: hidden=True

That way the Attribute Editor won't try to display it, which is where
the warning msg is coming from.


On Tue, Sep 30, 2008 at 12:41 PM, barnabas79 <elro...@gmail.com> wrote:
>

--
-deane

Paul Molodowitch

unread,
Oct 7, 2008, 12:08:43 PM10/7/08
to python_in...@googlegroups.com
Awesome, thanks... I actually tried that at one point, but kept
getting the warning message - though now I realize it's because the
warning was being triggered by the sample code (which also adds a
message attribute) as well. Heh...
- Paul
Reply all
Reply to author
Forward
0 new messages