Posted by:

For me namespaces were just a giant pain in the ass.  They always seemed to get in the way and they were always cropping up because maya likes to use them by default and even if you have them turned off on import they will still crop up due to cross version issues or references or how the file was saved last.  I never truly understood namespaces in Maya until I started writing scripts to deal with them.  I knew that they were there to prevent name clashes between different assets and that they manifest themselves as prefixes on all of the objects that they effect.  But what I didn’t understand is that namespaces are hierarchical organizations very much like those of a child parent relationship.  Namespaces aren’t just strings on the front of the object name, they are also a relationship.  I still don’t know exactly what they are.  They are not nodes, they are not DAG objects, they don’t appear in the Hypergraph.

Once you make friends with namespaces you can use them to your advantage.   Know that they are malleable, they can be created, combined and deleted.  You can use them to select the objects that reside in them.  You can move those objects from one namespace to another.  However, they are finicky, writing scripts to manipulate them is difficult.

Here is a script that I wrote to import all of the references in a scene and remove their namespaces:

  1. def importReference(*args):
  2. references = = 'reference')
  3. print('importReference(), the references are:' + str(references))
  4. exportFile = references.pop(0)
  5. references.append(exportFile)
  6. for eachReference in references:
  7. referenceFileName = cmds.referenceQuery(eachReference, filename = True)
  8. cmds.file(referenceFileName, importReference = True)
  10. cmds.namespace(set=':')#setting the namespace to the root
  11. namespaces = cmds.namespaceInfo(listOnlyNamespaces = True)#listing all namespaces in the scene
  12. for eachNamespace in namespaces:
  13. #removeNamespace and mergeNamespaceWithRoot work together to empty the namespace of objects (mergeNamespaceWithRoot) and then remove the namespace from the scene (removeNamespace)
  14. #you can't delete namespaces with objects in them.
  15. cmds.namespace(removeNamespace = eachNamespace, mergeNamespaceWithRoot = True)
  Related Posts
  • No related posts found.

You must be logged in to post a comment.