- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.