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