addAttr: -at vs -dt for float3 or double3 - A conundrum!

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  01 January 2014
Question addAttr: -at vs -dt for float3 or double3 - A conundrum!

Hi all,

I've searched here on CGTalk and Googled as well, and can't find a good answer to this.

Maya's docs for the addAttr command indicate that for adding an attribute of type float3 or double3, if you specify the type using the "-at" flag, the attr will be compound, and not compound if specified using "-dt".

Also, from the doc page directly:

Quote: In most cases the -dt version will not display in the attribute editor as it is an atomic type and you are not allowed to change individual parts of it. All attributes flagged as "(compound)" below or the compound attribute itself are not actually added to the node until all of the children are defined (using the "-p" flag to set their parent to the compound being created).

But when I add an attribute thusly:

 import pymel.core as pm
 myNode = pm.PyNode('locator1')
 pm.addAttr(myNode, sn='foo', dt='float3')

...performing a getAttr or getAttr -type yields a result of None.

Anybody know what's the scoop on this? All I want to do is add an attribute, using PyMEL, to an object to store a static XYZ coordinate. I don't need to access the component values individually, so I'd prefer not to have to use a compound attr.

  01 January 2014
just assign the needed data and it will work, also if you use float3 in the dt flag, getAttr will return the data as a python tuple, if you use double3, python will return the data as a pymel vector.

if you are working with the data in pymel the vector would be the preferable datatype to return.

    import pymel.core as pm
    cube = pm.PyNode('pCube1')
    cube.addAttr('testAttr', dt='float3')
    data = [0.5, 0.6, 0.7]
    print type(cube.testAttr.get())
    # <type 'tuple'>
    print cube.testAttr.get()
    # (0.5, 0.59999999999999998, 0.69999999999999996)

    import pymel.core as pm
    cube = pm.PyNode('pCube1')
    cube.addAttr('testAttr', dt='double3')
    data = [0.5, 0.6, 0.7]
    print type(cube.testAttr.get())
    # <class 'pymel.core.datatypes.Vector'>
    print cube.testAttr.get()
    # [0.5, 0.6, 0.7]

you should also make use of the object syntax more when using pymel, instead of getAttr and setAttr, you can simply access thigns like you would any other python object attribute, than use the get() and set() methods.

as a side note, if you create it this way, and not as a compound attribute, you will not be able to edit it in the channelBox or attributeEditor, you will only be able to get and set it;s data in code.
Twitter - GitHub
My Scripts - Maya tools and workflow scripts
psLink - Maya PhotoShop intergration.

Last edited by CMCPasserby : 01 January 2014 at 01:10 PM.
  01 January 2014
Just a short hint - sorry, I didn't read the previous post, as it seemed to me to be to long to answer the question:
  • open up the script editor, select "echo all commands" from the history menu
  • choose some arbitrary node in the outliner
  • in the attribute editor, select from menu "Attributes->Add Attributes"
  • type in a name for the new attribute, select vector, hit add
  • observe the output in the script editor:
addAttr -ln "test"  -at double3  defaultObjectSet;
 addAttr -ln "testX"  -at double -p test  defaultObjectSet;
 addAttr -ln "testY"  -at double -p test  defaultObjectSet;
 addAttr -ln "testZ"  -at double -p test  defaultObjectSet;
 setAttr -type double3 defaultObjectSet.test 0 0 0;

There you have a working example ... (obviously you have to prepare the child attributes before you can talk to your new compound attribute).
  01 January 2014
Thumbs up Solved


Thank you for your reply; it was very helpful. The Maya docs should be updated to note that using the -dt flag in attribute creation requires a small leap of faith! I tried out what you suggested and it worked as you have said.

N.B.: in the end I had to go with using the -at flag, and three child attrs added separately. The reason is that the attr I'm adding is to be used as input to an attr on a custom DAG node I've written; the destination attr in question is created via

numericAttributeFn = OpenMaya.MFnNumericAttribute()
 myDagNode.myInputAttr = numericAttributeFn.createPoint('myLongName', 'myShortName')

Maya does not allow me to connect an attr created with dt='float3' or 'double3' to myDagNode.myInputAttr above, I think due to the 'atomic' nature of the source attr. If you know of any other method of creating a float/double vector or tuple type attr via the Python API, I'd be interested in hearing of it.

Thanks again.
  01 January 2014
Thread automatically closed

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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 05:44 PM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.