Issue 138 in pymel: feature req: addAttr doesn't return an attribute

25 views
Skip to first unread message

codesite...@google.com

unread,
Dec 31, 2009, 5:22:06 PM12/31/09
to py...@googlegroups.com
Status: New
Owner: ----

New issue 138 by macaronikazoo: feature req: addAttr doesn't return an
attribute
http://code.google.com/p/pymel/issues/detail?id=138

would be nice if when I do:

someNode.addAttr(...)

pymel would return the attribute object - save me having to do a getattr(
someNode ... )

--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

codesite...@google.com

unread,
Jan 4, 2010, 5:40:22 PM1/4/10
to py...@googlegroups.com
Updates:
Labels: Type-Enhancement

Comment #1 on issue 138 by chadrik: feature req: addAttr doesn't return an
attribute
http://code.google.com/p/pymel/issues/detail?id=138

this appears to be slightly more complicated than one might assume, for a
couple of
reasons

1. an attribute can be created on more than node at a time: the result
must be a list
of Attributes
2. cmds.addAttr does not return the name of the attribute just created: we
have to
piece it together from the passed arguments/flags/selected nodes
3. compound attributes and their children are invalid until all children
are created:
are we comfortable with the inconsistency of not returning a result for
compound
types?

the third is the biggest issue. for example:


cmds.addAttr( 'persp', longName='rainbow', usedAsColor=True,
attributeType='float3' )
PyNode( 'persp.rainbow' ) #<---- raises a MayaObjectError
cmds.addAttr( 'persp', longName='redBow', attributeType='float',
parent='rainbow' )
cmds.addAttr( 'persp', longName='greenBow', attributeType='float',
parent='rainbow'
)
cmds.addAttr( 'persp', longName='blueBow', attributeType='float',
parent='rainbow' )
PyNode( 'persp.rainbow' ) #<---- works

one potential solution, add a shorthand for creating compound types:

addAttr( 'persp', longName='rainbow', usedAsColor=True,
attributeType='float3',
children=['redBow', 'greenBow', 'blueBow'] )

but this would also have to do mixed compound types:

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'
)

perhaps:

cmds.addAttr( longName='sampson', numberOfChildren=5,
attributeType='compound', children=[ ( 'homeboy', 'matrix' ),

( 'midge', 'message'),

( 'damien', 'double'),

( 'elizabeth', 'double' ),

( 'sweetpea', 'double' ) ] )

this is something that will take a lot of testing to make sure we every
combination
works right.

codesite...@google.com

unread,
Jan 4, 2010, 5:50:37 PM1/4/10
to py...@googlegroups.com
Updates:
Status: Accepted
Owner: chadrik
Labels: Milestone-1.0.x

Comment #2 on issue 138 by chadrik: feature req: addAttr doesn't return an
attribute
http://code.google.com/p/pymel/issues/detail?id=138

(No comment was entered for this change.)

barnabas79

unread,
Jan 5, 2010, 12:05:26 PM1/5/10
to Pymel Python Module for Maya
I'm actually not sold on this, because of the compound attribute
issue. While it would be nice, the inconsistent behavior of addAttr
is going to lead to bugs in people's code. ie, people will get used
to assuming that addAttr returns an attribute (since it does in most
cases), and so - even if they're AWARE of the exception, which most
people probably won't be - will inevitably forget it when they make a
compound attribute. The shorthand syntax would help (and would be a
nice idea, regardless of the return value issue), but isn't really a
complete solution, as long as the other, "standard" way of creating
attributes is there... which it will probably have to be

Besides, as long as you've got access to the PyNode you're adding the
attribute to (which you generally will - relying on the selection is
generally a bad idea, programatically), it's not much extra work to
do:

myNode.myAttr

or

myNode.attr('myAttr')

If we are going to go with this, though - or if we just add the
ability to use a 'children' flag for compound attributes - I would
recommend changing the syntax to:

addAttr( longName='sampson', numberOfChildren=5,
attributeType='compound',

children=[ {longName='homeboy', attributeType='matrix',
keyable=False},
{ln='midge', at='message'},
{longName='damien', dataType='double'}])

A little less shorthand, but easier to implement, more powerful/
flexible, a little more readable, and more consistent with existing
syntax.

(Sorta another feature, but if we're going to implement the ability to
auto-detect whether an attribute's 'type' is a dataType,
attributeType, might as well add that into the normal addAttr, as
another flag... perhaps called 'type'? Only drawback with that name
is it overrides a builtin...)

Chad Dombrova

unread,
Jan 5, 2010, 12:12:24 PM1/5/10
to py...@googlegroups.com
hey paul, you might want to post this in the issue thread. btw, i'm going to be disabling issue and svn notifications through this googlegroup in favor of RSS feeds to prevent this sort of confusion.

-chad

> --
> You received this message because you are subscribed to the Google Groups "Pymel Python Module for Maya" group.
> To post to this group, send email to py...@googlegroups.com.
> To unsubscribe from this group, send email to pymel+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pymel?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages