Creating maya nodes with invalid names
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
We hit a sweet bug in Maya today where an artist created a node in the scene with an invalid name upon combining objects. (polyUnite) I was unable to reproduce that actual case that actually happened through regular Maya actions like just using mesh combine, so looked into reproducing it through code.
To debug it I produced this reproducable case by just creating a polyCube:
from maya import cmds
cmds.polyCube(name="hello.world[0:5]")
Tested in Maya 2020.4 and Maya 2022 this creates a node called: :hello_world_0:5]
You can select it in the outliner, however you cannot rename, delete or hide it. Basically most maya commands will tell you it's working with an invalid node name and won't do anything. Even abusing the API to delete the node fails. E.g. selecting the node and trying:
import maya.api.OpenMaya as om
sel = om.MGlobal.getActiveSelectionList()
node = sel.getDependNode(0)
om.MGlobal.deleteNode(node)
Or older Python API:
import maya.OpenMaya as om
sel = om.MSelectionList()
om.MGlobal.getActiveSelectionList(sel)
node = om.MObject()
sel.getDependNode(0, node)
om.MGlobal.deleteNode(node)
Here's some others tripping up Maya:
from maya import cmds
cmds.polyCube(name="0")
cmds.polyCube(name="]")
cmds.polyCube(name="'.")
Also names consisting of solely numbers, a space or special characters:
from maya import cmds
cmds.polyCube(name="222")
cmds.polyCube(name=" ")
cmds.polyCube(name="\n")
cmds.polyCube(name="\t")
It looks like other invalid leading tokens are stripped if there is a character like "[a" gets converted to "a". So the error checking only seems to happen if a valid string can be produced, otherwise you just get what you get.
It also fails to keep the object names unique:
from maya import cmds
cmds.polyCube(name="222")
cmds.polyCube(name="222")
cmds.polyCube(name="[")
cmds.polyCube(name="[")
Workaround to delete the invalid nodes:
There is a workaround delete the nodes. Select them in the viewport or outliner and do a CUT action (e.g. CTRL + X)
Or selecting the nodes, and running this in Python:
from maya import cmds
cmds.delete()
Also, as long as you try selecting and deleting without mentioning the nodes by name, you can:
from maya import cmds
cmds.select(all=True) # this only selects root nodes!
cmds.select("*", deselect=True)
cmds.delete()
Deleting them through the API like this does work:
import maya.api.OpenMaya as om
sel = om.MGlobal.getActiveSelectionList()
mod = om.MDGModifier()
for i in range(sel.length()):
node = sel.getDependNode(i)
mod.deleteNode(node)
mod.doIt()