[Maya-Python] creating sub attributes

1,088 views
Skip to first unread message

shawnpatapoff

unread,
May 25, 2010, 12:37:24 PM5/25/10
to python_inside_maya
Anyone know how to make sub attributes at all, or is it possible?

What I'm trying to do is.

object.myAttr.subAttr

I'm using .message for my connections, not sure if it's even possible.

Cheers,
Shawn

--
http://groups.google.com/group/python_inside_maya

David Moulder

unread,
May 25, 2010, 2:00:36 PM5/25/10
to python_in...@googlegroups.com
I think your after a compound attribute. I'm not sure if a message
link can be a compound attribute tho.

FYI

http://www.rtrowbridge.com/blog/2009/03/python-api-compound-attribute/

-Dave
--
David Moulder
http://www.google.com/profiles/squish3d

--
http://groups.google.com/group/python_inside_maya

shawnpatapoff

unread,
May 25, 2010, 3:02:41 PM5/25/10
to python_inside_maya
Hey David,

Looks like compound is the way to go, a bit of a pain to manage but it
does what I was looking for. And you can use '.message'

Cheers,
Shawn

On May 25, 11:00 am, David Moulder <da...@thirstydevil.co.uk> wrote:
> I think your after a compound attribute.  I'm not sure if a message
> link can be a compound attribute tho.
>
> FYI
>
> http://www.rtrowbridge.com/blog/2009/03/python-api-compound-attribute/
>
> -Dave
>

shawnpatapoff

unread,
May 26, 2010, 7:33:36 PM5/26/10
to python_inside_maya
Just to add to the discussing. I'm have some odd issues with nesting
attributes as in they don't seem to get created reliable.

c1 = polyCube()[0]
c1.addAttr('Anim', nc=1, at='compound')
print c1.hasAttr('Anim')
#result False
c1.addAttr('Attr_A', nc=1 ,at='compound',parent='Anim')
print c1.hasAttr('Anim')
#result False
c1.addAttr('Attr_B', nc=1, at='compound', parent = 'Attr_A')
print c1.hasAttr('Anim')
#result False
c1.addAttr('Attr_C', at='message', parent='Attr_B')
print c1.hasAttr('Anim')
#result True

So the the entire structure doesn't exist until 'Attr_C' is added. Is
there something wrong in my logic?

Cheers,
Shawn

David Moulder

unread,
May 27, 2010, 5:21:51 AM5/27/10
to python_in...@googlegroups.com
Compound attrs don't seem to be real attrs at all. More like a
grouping system for attributes. So really all attributes are created
at the root level.
See below...

-Dave

import pymel.core as pCore
Cube = pCore.PyNode("pCube1")

# Compund Attrs are effectively null containers and NOT attributes per say.
Cube.addAttr('CompoundLevel1', nc=1, at='compound')
Cube.addAttr('CompoundLevel2', nc=1, at='compound')
Cube.addAttr('CompoundLevel3', nc=1, at='compound')

# Hence this returns False
print Cube.hasAttr("CompoundLevel1")
print Cube.hasAttr("CompoundLevel2")
print Cube.hasAttr("CompoundLevel3")

# Now add some real attributes
Cube.addAttr("MessageA", at='message', parent='CompoundLevel1')
# Now query if the Compound exists...
print Cube.hasAttr("CompoundLevel1")
# >> True

# But all attributes are really at the root level and compound
# attrs are a fictional grouping mechanism
print Cube.MessageA.outputs()
# >> []

# You can also access from the longName
print Cube.CompoundLevel1.MessageA.outputs()
# >> []

# Lets see if there is an Error if we try to put a attr onto
# the Cube with the same name but in a different compound level
Cube.addAttr("MessageA", at='message', parent='CompoundLevel2')

# Warning: Name 'MessageA' of new attribute clashes with an existing
attribute of node 'pCube1'. #
# Error: Found no valid items to add the attribute to.
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# File "C:/ArtPipelines/App/Maya2011-x64/pymel/pymel\pymel\core\nodetypes.py",
line 436, in addAttr
# return general.addAttr( unicode(self), **kwargs )
# File "C:/ArtPipelines/App/Maya2011-x64/pymel/pymel\pymel\core\general.py",
line 619, in addAttr
# res = cmds.addAttr( *args, **kwargs )
# File "C:/ArtPipelines/App/Maya2011-x64/pymel/pymel\pymel\internal\pmcmds.py",
line 98, in wrappedCmd
# res = new_cmd(*new_args, **new_kwargs)
# RuntimeError: Found no valid items to add the attribute to. #

shawnpatapoff

unread,
May 27, 2010, 12:07:25 PM5/27/10
to python_inside_maya
Hey Dave,

Thanks for the info. I'll have to weight the pros and cons if I want
to use this in our pipe or not. The grouping doesn't really seem to
work like I had hoped it would.

Cheers,
Shawn

Judah Baron

unread,
May 27, 2010, 3:21:55 PM5/27/10
to python_in...@googlegroups.com
It's true. All attributes are created equal. Compound attributes are
largely a nicity for the user, be that an artist using the ui, or a
programmer organizing data in a way that makes sense to a human. If
anyone cares to test this just try creating a compound attribute that
has a child attribute with the same name as another attribute on the
node, but under a different parent attr. It turns out you can't do
this, as the child name of the attribute is used to find it, not the
child name scoped by the parental prefix. If you have a lot of similar
attributes, such as transform data, or various color containers on a
material you have to come up with a creative naming solution. This is
probably why so many of the factory nodes have such ridiculously long
names:)

-Judah


On May 27, 2010, at 5:21 AM, David Moulder <da...@thirstydevil.co.uk>
wrote:

> --
> http://groups.google.com/group/python_inside_maya

Reply all
Reply to author
Forward
0 new messages