Maya API: Removing namespaces makes anim data go missing


#1

I have a scene of an animated rig made up of referenced objects. Namespaces needs to get cleaned away prior to the scene being exported but doing so seems to disconnect some node I wasn’t aware of, resulting in animation data going missing once you re-open the Maya-scene.

What I do:
I loop thru all joints (MFnIkJoint) and transforms (MFnTransform) in the scene and add them to two lists. I then loop thru these lists and just look for the namespace prefix(es). I save the old name and then I strip away the namespace like here below, export and then I restore the name to it’s original name.

# obj - the joint or transform object
import re
nameList = re.split("[:]", obj.name())
if len(nameList) != 1:  # Has namespace prefix
    obj.setName(nameList[-1])

It appears that when I do this rename, some other node connection gets disconnected. So when the scene is saved after export, and later re-opened, the animations are GONE and the character is back in T-pose. Everything looks fine in the Outliner and in the Namespace editor (ie: it looks like how it did prior to exporting).

Now I’m no expert on rigging and animations so I’m not exactly sure what nodes are affected (disconnected) by this forced renaming. All help is appreciated.¨

What I want to know:
-What nodes are losing their connection(s) when I do the above? It’s more than just the joints and transforms.
-Can the lost connections be retrieved?


#2

Cause found:
The animatable attributes translateX, translateY, translateZ, rotateX, etc… and visibility - where all disconnected from the root controller (animCurve). So by connecting these again the animations were restored.

Re-connection example (using cmds.connectAttr in this case, with flag force=True):
animation_root_controller_translateZ >> |some_namespace:animation_root_controller.translateZ

So:

cmds.connectAttr(animation_root_controller_translateZ, |some_namespace:animation_root_controller.translateZ, force=True)


(formatting error - space before teZ - caused by the CGTalk post message rules)


#3

Depending on how your namespaces are laid out, there might be an easier way. If all the nodes you want to export are contained within a single namespace, you can use the -relativeNamespace flag on the file command. When specified, you supply the namespace you want to export from and it will treat that namespace as the current namespace when exporting and as a result no namespaces will be exported.

This won’t work however if you have nodes in multiple namespaces.