Maya python, use selected namespace as parent and add new namespace (file name)

I’m trying to figure out how to import and merge an animation fbx file into a referenced rig with a unique namespace. I can do it manually in the import options but I’m not sure how to do that through code.
image

Does anyone know the way to do this?

Ah I figured it out at least for merging an FBX files animation into a referenced rig

# Set the current namespace
cmds.namespace( set='Rig01' )
filepath = "D:/folder/filename.fbx"

if os.path.exists(filepath):
    try:
        cmds.file (filepath, i=True, type="FBX", ignoreVersion=False, renameAll=True, mergeNamespacesOnClash=False, namespace="", preserveReferences=True, importTimeRange="combine")
    except Exception as e:
        cmds.warning("Could not import: " + filepath + ";\n" + str(e))

This won’t work for a mayaBinary file however but at the very least I can merge the correct animations and create the animation layers after.

1 Like