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)
More than 1 year has passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme