0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

python maya change namespace

Posted at
import maya.cmds as cmds

def get_all_namespaces():
    namespaces = cmds.namespaceInfo(listOnlyNamespaces=True, recurse=True)
    return namespaces
    
def change_namespace(old_namespace, new_namespace):
    # Get a list of objects in the old namespace
    objects = cmds.namespaceInfo(old_namespace, listOnlyDependencyNodes=True, dagPath=True)

    # Create the new namespace
    cmds.namespace(add=new_namespace)

    # Rename the objects to the new namespace
    for obj in objects:
        new_name = obj.replace(old_namespace + ':', new_namespace + ':')
        cmds.rename(obj, new_name)

    # Remove the old namespace
    cmds.namespace(removeNamespace=old_namespace, mergeNamespaceWithRoot=True)

all_namespaces = get_all_namespaces()
print(all_namespaces)

map = {
    
    "s033": "step_002",
    "280": "004",
}

keys = map.keys()
for n in all_namespaces:
    renameJob = False
    newname = n
    for k in keys:
        if k in n:
            #print(n)
            newname = n.replace(k, map[k])
            renameJob=True
    if not renameJob: continue
    print(newname)
    change_namespace(n, newname)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?