Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Maya 2024.2 update and node attribute naming

Maya 2024.2 update and node attribute naming

golaem
Enthusiast Enthusiast
1,175 Views
5 Replies
Message 1 of 6

Maya 2024.2 update and node attribute naming

golaem
Enthusiast
Enthusiast

Hello,

Since the Maya 2024.2 update, we've noticed that node attribute names starting with a digit are not allowed anymore in the Maya API. This has worked fine in Maya 2024.1 and all the previous Maya versions since at least Maya 2016.

 

Here's an example plugin in Python to illustrate the issue:

 

# sampleNode.py

import sys

import maya.api.OpenMaya as OpenMaya

def maya_useNewAPI():
    """
    The presence of this function tells Maya that the plugin produces, and
    expects to be passed, objects created using the Maya Python API 2.0.
    """
    pass

# Plug-in information:
kPluginNodeName = 'sampleNode'              # The name of the node.
kPluginNodeClassify = 'utility/general'     # Where this node will be found in the Maya UI.
kPluginNodeId = OpenMaya.MTypeId(0x00000001) # A unique ID associated to this node type.

##########################################################
# Plug-in 
##########################################################
class sampleNode(OpenMaya.MPxNode):
    # Static variables which will later be replaced by the node's attributes.
    sampleAttribute = OpenMaya.MObject()

    def __init__(self):
        OpenMaya.MPxNode.__init__(self)

##########################################################
# Plug-in initialization.
##########################################################
def nodeCreator():
    ''' Creates an instance of our node class and delivers it to Maya as a pointer. '''
    return  sampleNode() 

def nodeInitializer():
    ''' Defines the input and output attributes as static variables in our plug-in class. '''

    # The following MFnNumericAttribute function set will allow us to create our attributes.
    numericAttributeFn = OpenMaya.MFnNumericAttribute()

    sampleNode.sampleInAttribute = numericAttributeFn.create("1stAttr", 'fatr', OpenMaya.MFnNumericData.kFloat, 0)
    numericAttributeFn.writable = True 
    numericAttributeFn.storable = True 
    numericAttributeFn.hidden = False 
    sampleNode.addAttribute(sampleNode.sampleInAttribute) # Calls the MPxNode.addAttribute function.


def initializePlugin(mobject):
    ''' Initialize the plug-in '''
    mplugin = OpenMaya.MFnPlugin( mobject )
    try:
        mplugin.registerNode(kPluginNodeName, kPluginNodeId, nodeCreator, nodeInitializer, OpenMaya.MPxNode.kDependNode, kPluginNodeClassify )
    except:
        sys.stderr.write('Failed to register node: ' + kPluginNodeName)
        raise

def uninitializePlugin( mobject ):
    ''' Uninitializes the plug-in '''
    mplugin = OpenMaya.MFnPlugin(mobject)
    try:
        mplugin.deregisterNode(kPluginNodeId)
    except:
        sys.stderr.write( 'Failed to deregister node: ' + kPluginNodeName )
        raise

##########################################################
# Sample usage.
##########################################################
"""
# Copy the following lines and run them in Maya's Python Script Editor:

import maya.cmds as cmds
cmds.loadPlugin("[parentDir]/sampleNode.py")
createdNode = cmds.createNode("sampleNode")

# get the attribute
cmds.getAttr(createdNode + ".1stAttr")
# ...

"""

 

To test the node, just save the code to a file called sampleNode.py and use the following code (replace the [parentDir]  with the directory of the file):

 

import maya.cmds as cmds
cmds.loadPlugin("[parentDir]/sampleNode.py")
createdNode = cmds.createNode("sampleNode")

# get the attribute
cmds.getAttr(createdNode + ".1stAttr")

 

As you can see, the node contains an attribute called "1stAttr". If you execute the code above in Maya 2024.2 it will fail: 

cmds.getAttr(createdNode + ".1stAttr")
# Error: Object sampleNode1.1stAttr is invalid
# # Traceback (most recent call last):
# #   File "<maya console>", line 1, in <module>
# # TypeError: Object sampleNode1.1stAttr is invalid

We also noticed that Maya 2024.2 silently renames "sampleNode1.1stAttr" to "sampleNode1.stAttr" (removes the first digit).

 

In Maya 2024.1 and all the previous Maya versions this works with no issue.

 

Is this behavior expected in Maya 2024.2, or is it a regression? 

 

Best regards,

 

The Golaem team

0 Likes
Accepted solutions (1)
1,176 Views
5 Replies
Replies (5)
Message 2 of 6

brentmc
Autodesk
Autodesk

Hi,

The change was done to fix an issue where you could create an attribute whose name only contained numbers which was allowed but then generated errors later on.

So the change was deliberate but I'm checking to see whether names that start with a number should be allowed. (because they are not allowed for object names in Maya)

 

Thanks.

Brent McPherson
Principle Engineer
0 Likes
Message 3 of 6

golaem
Enthusiast
Enthusiast

Hi Brent,

 

Thank you for your answer. Indeed, it would be good to know if attribute names starting with a number should be allowed. In case this should not be allowed, it would be nice to have an error message in the node initialize function to avoid using invalid names.

 

Thanks

0 Likes
Message 4 of 6

brentmc
Autodesk
Autodesk
Accepted solution

Hi,

 

Unfortunately the person who fixed this is no longer around and I haven't heard anything else so I think you should not use attribute names starting with a number going forward. (as the change was also made to make node and attributes name validation more consistent)

It is listed in the 2024.2 release notes
MAYA-128899:  Update the attribute creation process to check for valid naming
https://help.autodesk.com/view/MAYAUL/2024/ENU/?guid=MAYA_RELEASENOTES_2024_2_RELEASE_NOTES_HTML

If you try to create an attribute that start with a number you should see an error like this:

# Error: RuntimeError: file <maya console> line 13: (kInvalidParameter): Invalid attribute name

 

Thanks.

Brent McPherson
Principle Engineer
0 Likes
Message 5 of 6

golaem
Enthusiast
Enthusiast

Ok, thanks for the info. We'll change our code to remove these attributes and make sure we don't use invalid names in the future. 

 

Best regards,

0 Likes
Message 6 of 6

brentmc
Autodesk
Autodesk

Thanks!

Brent McPherson
Principle Engineer