Go to: Synopsis. Return value. Related. Flags. Python examples.

Synopsis

namespace( [string] , [addNamespace=string], [exists=string], [force=boolean], [moveNamespace=[string, string]], [parent=string], [removeNamespace=string], [setNamespace=string])

Note: Strings representing object names and arguments must be separated by commas. This is not depicted in the synopsis.

namespace is undoable, NOT queryable, and NOT editable.

This command allows a namespace to be created or set or removed.

A namespace is a simple grouping of objects under a given name. Namespaces are primarily used to resolve name-clash issues in Maya, where a new object has the same name as an existing object (from importing a file, for example). Using namespaces, you can have two objects with the same name, as long as they are contained in differenct namespaces.

Namespaces are reminiscent of hierarchical structures like file systems where namespaces are analogous to directories and objects are analogous to files. The colon (':') character is the separator used to separate the names of namespaces and nodes instead of the slash ('/') or backslash ('\') character. Namespaces can contain other namespaces as well as objects. Like objects, the names of namespaces must be unique within another namespace. Objects and namespaces can be in only one namespace. Namespace names and object names don't clash so a namespace and an object contained in another namespace can have the same name.

There is an unnamed root namespace specified with a leading colon (':'). Any object not in a named namespace is in the root namespace. Normally, the leading colon is omitted from the name of an object as it's presence is implied. The presence of a leading colon is important when moving objects between namespaces using the 'rename' command. For the 'rename' command, the new name is relative to the current namespace unless the new name is fully qualified with a leading colon.

Namespaces are created using the add/addNamespace flag. They are created under the current namespace. Changing the current namespace is done with -set/setNamespace flag. To reset the current namespace to the root namespace, use 'namespace -set ":";'. Whenever an object is created, it is added to the current namespace.

Return value

string

Related

namespaceInfo

Flags

addNamespace, exists, force, moveNamespace, parent, removeNamespace, setNamespace
Long name (short name) Argument types Properties
addNamespace(add) string create
Create a new namespace with the given name.
exists(ex) string create
Returns true if the specified namespace exists, false if not.
force(f) boolean create
Used with -mv/-moveNamespace to force the move operation to ignore name clashes.
moveNamespace(mv) [string, string] create
Move the contents of the first namespace into the second namespace. Child namespaces will also be moved.

Attempting to move a namespace containing referenced nodes will result in an error - use the 'file -e -namespace' command to change a reference namespace.

If there are objects in the source namespace with the same name as objects in the destination namespace, an error will be issued. Use the '-force' flag to override this error - name clashes will be resolved by renaming the objects to ensure uniqueness.
parent(p) string create
Used with the -add/-addNamespace to specifiy the parent of the new namespace.
removeNamespace(rm) string create
Deletes the given namespace. The namespace must be empty for it to be deleted.
setNamespace(set) string create
Sets the current namespace.

Flag can appear in Create mode of command Flag can appear in Edit mode of command
Flag can appear in Query mode of command Flag can have multiple arguments, passed either as a tuple or a list.

Python examples

import maya.cmds as cmds

# Create three namespaces
cmds.namespace( add='FOO' )
cmds.namespace( add='BAR' )
cmds.namespace( add='FRED' )

# Set the current namespace to FOO
cmds.namespace( set='FOO' )

# Create the namespace BAR Under FOO. Note there are
# two "BAR" namespaces, :BAR and :FOO:BAR.
cmds.namespace( add='BAR' )

# Check to see that the BAR namespace exists within the current
# namespace (FOO)
cmds.namespace( exists='BAR' )
# Result: 1 #

# Check to see that the FRED namespace exists under the root namespace
cmds.namespace( exists=':FRED' )
# Result: 1 #

# Create two objects. It gets added to the current namespace FOO;
cmds.sphere( n='sphere1' )
cmds.sphere( n='sphere2' )
# Result: FOO:sphere2 #

# Move sphere1 from namespace FOO to FOO:BAR. Note that we
# need to qualify sphere1 with the namespace FOO because
# "sphere1" identifies a non-existent object in the root namespace.
cmds.rename( 'FOO:sphere1', 'BAR:sphere1' )
# Result: FOO:BAR:sphere1 #

# Move sphere2 from namespace FOO to BAR.  Note the leading
# colon on the new name.
cmds.rename( 'FOO:sphere2', ':BAR:sphere2' )
# Result: BAR:sphere2 #

# query the current namespace (using the namespaceInfo command)
cmds.namespaceInfo( currentNamespace=True )
# Result: FOO #

# remove the namespace FRED (it must be empty)
cmds.namespace( set=':' )
cmds.namespace( rm='FRED' )

# Check to see that the FRED namespace has been removed
cmds.namespace( exists=':FRED' )
# Result: 0 #

# Rename namespace BAR to JOE
# Note: this is done by creating JOE, moving the contents of
# BAR into JOE, and then removing the (now empty) BAR.
cmds.namespace( set=':' )
cmds.namespace( add='JOE' )
cmds.namespace( mv=('BAR', 'JOE') )
cmds.namespace( rm='BAR' )

# JOE should now contain a single node: 'sphere2'.
# Move the contents of JOE into FRANK, when FRANK already
# has a 'sphere2' node. The '-force'
# flag is needed.
cmds.namespace( set=':' )
cmds.namespace( add='FRANK' )
cmds.namespace( set='FRANK' )
cmds.sphere( n='sphere2' )
cmds.namespace( force=True, mv=(':JOE', ':FRANK') )
# In moving 'sphere2' from JOE to FRANK it will be renamed to
# 'sphere3' to ensure uniqueness.
# The naemspace FRANK should now contain 'sphere2', 'sphere2Shape',
# and 'sphere3'.