[Python] addAttr fail to create float2 attribute into compound attribute

[Python] addAttr fail to create float2 attribute into compound attribute

Anonymous
Not applicable
1,622 Views
2 Replies
Message 1 of 3

[Python] addAttr fail to create float2 attribute into compound attribute

Anonymous
Not applicable

Hello,

I want to create a compound attribute with several float2 attributes inside (as extra attributes of a transform node).

It works well with float3 attributes :

cmds.addAttr(longName='compoundAttr', numberOfChildren=1, attributeType='compound')
cmds.addAttr(longName='sup', attributeType='float3', parent='sampson')
cmds.addAttr(longName='sub1', attributeType='float', parent='sup')
cmds.addAttr(longName='sub2', attributeType='float', parent='sup')
cmds.addAttr(longName='sub3', attributeType='float', parent='sup')

float3.png

But it fails when I use a float2 instead of float3 :

cmds.addAttr(longName='coumpoundAttr', numberOfChildren=1, attributeType='compound')
cmds.addAttr(longName='sup', attributeType='float2', parent='coumpoundAttr')
cmds.addAttr(longName='sub1', attributeType='float', parent='sup')
cmds.addAttr(longName='sub2', attributeType='float', parent='sup')

float2.png

I am doing something wrong ?

Thanks a lot.

0 Likes
1,623 Views
2 Replies
Replies (2)
Message 2 of 3

RFlannery1
Collaborator
Collaborator

It looks like the template for adding new compound attributes to the Attribute Editor does not account for float2 attributes.  So here's what you can do:

  1. Find the file "C:\Program Files\Autodesk\Maya2016\scripts\AETemplates\AEnewCompound.mel" (or wherever is located for your installation of Maya.
  2. Make a copy of it in your user script directory.  Do not edit the original!
  3. In your copy of the file, in the proc "AEnewCompound", add the following lines to the section where it is checking for the child attribute types:
    else if( $childType == "float2" )
    {
        AEnewVector($childPlug, $childAttrNice, $changedCommand);
    }
  4. Restart Maya, if it was open while you made these changes.

 

These steps will make the attribute appear the way you want it to.  I haven't tested it any further than that, so you'll have to make sure that the new attribute works the way you expect, i.e. values are updated as expected, attribute connections work, Maya doesn't start acting weird or crash.

 

Edit:  Important note:  These changes will only be on your local machine.  So you could make a file with this compound attribute and save it.  But if you then go to someone else's machine, and they don't have your custom code, when the file is opened on that machine, the attribute will appear like your original problem.

0 Likes
Message 3 of 3

Anonymous
Not applicable

Hi, thanks for the answer, I'm gonna test that asap.

Best regards,

0 Likes