Go to: Synopsis. Return value. Related. Flags. MEL examples.
namespace [-absoluteName] [-addNamespace string] [-collapseAncestors string] [-deleteNamespaceContent] [-exists string] [-force] [-isRootNamespace string] [-mergeNamespaceWithOther string] [-mergeNamespaceWithParent] [-mergeNamespaceWithRoot] [-moveNamespace string string] [-parent string] [-recurse] [-relativeNames boolean] [-removeNamespace string] [-rename string string] [-setNamespace string] [-validateName string]
[string]
namespace is undoable, queryable, and NOT editable.
This command allows a namespace to be created, 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. By default they are created under the current namespace. Changing the current namespace is done with the 'set/setNamespace' flag. To reset the current namespace to the root namespace, use 'namespace -set ":";'. Whenever an object is created, it is added by default to the current namespace. When creating a new namespace using a qualified name, any intervening namespaces which do not yet exist will be automatically created. For example, if the name of the new namespace is specified as "A:B" and the current namespace already has a child namespace named "A" then a new child namespace named "B" will be created under "A". But if the current namespace does not yet have a child named "A" then it will be created automatically. This applies regardless of the number of levels in the provided name (e.g. "A:B:C:D"). The 'p/parent' flag can be used to explicitly specify the parent namespace under which the new one should be created, rather than just defaulting to the current namespace. If the name given for the new namespace is absolute (i.e. it begins with a colon, as in ":A:B") then both the current namespace and the 'parent' flag will be ignored and the new namespace will be created under the root namespace. The relativeNamespace flag can be used to change the way node names are displayed in the UI and returned by the 'ls' command. Here are some specific details on how the return from the 'ls' command works in relativeNamespace mode:string | Command result |
In query mode, return type is based on queried flag.
Long name (short name) | Argument types | Properties | ||
---|---|---|---|---|
-absoluteName(-an)
|
|
|||
|
||||
-addNamespace(-add)
|
string
|
|||
|
||||
-collapseAncestors(-ch)
|
string
|
|||
|
||||
-deleteNamespaceContent(-dnc)
|
|
|||
|
||||
-exists(-ex)
|
string
|
|||
|
||||
-force(-f)
|
|
|||
|
||||
-isRootNamespace(-ir)
|
string
|
|||
|
||||
-mergeNamespaceWithOther(-mno)
|
string
|
|||
|
||||
-mergeNamespaceWithParent(-mnp)
|
|
|||
|
||||
-mergeNamespaceWithRoot(-mnr)
|
|
|||
|
||||
-moveNamespace(-mv)
|
string string
|
|||
|
||||
-parent(-p)
|
string
|
|||
|
||||
-recurse(-r)
|
|
|||
|
||||
-relativeNames(-rel)
|
boolean
|
|||
|
||||
-removeNamespace(-rm)
|
string
|
|||
|
||||
-rename(-ren)
|
string string
|
|||
|
||||
-setNamespace(-set)
|
string
|
|||
|
||||
-validateName(-vn)
|
string
|
|||
|
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 be used more than once in a command. |
// Create three namespaces namespace -add "FOO"; namespace -add "BAR"; namespace -add "FRED"; // Create namespace with qualified name namespace -add "A:B"; // Create "C:D" under "A:B" namespace -add "C:D" -parent "A:B"; // Create absolute name namespace -add ":A:B:C:D:E"; // Set the current namespace to FOO namespace -set "FOO"; // Create the namespace BAR Under FOO. Note there are // two "BAR" namespaces, :BAR and :FOO:BAR. namespace -add "BAR"; // Validate the name namespace -validateName "name$space"; // Result : name_space // Check to see that the BAR namespace exists within the current // namespace (FOO) namespace -exists "BAR"; // Result: 1 // // Check to see that the FRED namespace exists under the root namespace namespace -exists ":FRED"; // Result: 1 // // Create two objects. It gets added to the current namespace FOO; sphere -n sphere1; 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. rename FOO:sphere1 "BAR:sphere1"; // Result: FOO:BAR:sphere1 // // Move sphere2 from namespace FOO to BAR. Note the leading // colon on the new name. rename FOO:sphere2 :BAR:sphere2; // Result: BAR:sphere2 // // query the current namespace (using the namespaceInfo command) namespaceInfo -currentNamespace; // Result: FOO // // remove the namespace FRED (it must be empty) namespace -set ":"; namespace -rm "FRED"; // Check to see that the FRED namespace has been removed 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. namespace -set ":"; namespace -add "JOE"; namespace -mv "BAR" "JOE"; 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. namespace -set ":"; namespace -add "FRANK"; namespace -set "FRANK"; sphere -n "sphere2"; namespace -force -mv ":JOE" ":FRANK"; // In moving 'sphere2' from JOE to FRANK it will be renamed to // 'sphere3' to ensure uniqueness. // The namespace FRANK should now contain 'sphere2', 'sphere2Shape', // and 'sphere3'. // Determine whether the specified namespace is root // namespace -query -isRootNamespace "FOO"; //Set return value to be absolute namespace name // string $retName = `namespace -add "testAbsoluteName" -absoluteName`; print $retName; //Create a sample hierachy that contains only empty namespaces, then collapse it // namespace -set ":"; namespace -add "emptyLevel1"; namespace -add "emptyLevel2" -parent "emptyLevel1"; namespace -add "leaf" -parent "emptyLevel1:emptyLevel2"; namespace -collapseAncestors "emptyLevel1:emptyLevel2:leaf"; // Create a sample for "namespace -remove" command. // This command can also be used together with these option flags: // -deleteNamespaceContent // -mergeNamespaceWithParent // -mergeNamespaceWithRoot // -mergeNamespaceWithOther // // The functionality of the option flags will also be displayed in the // following sample. // Note: The three option flags are mutually exclusive. // The default way the "namespace -remove" acts is that it is used to // remove a namespace that is empty. If you want to remove any namespace // with contents, please add option flag -deleteNamespaceContent. // namespace -set ":"; namespace -add ":RM_TEST_ROOT:FOO:BAR:JOE"; sphere -n ":RM_TEST_ROOT:FOO:obj1"; sphere -n ":RM_TEST_ROOT:FOO:BAR:obj2"; // Trying to remove a namespace that is not empty without option flag, // user will get an error message show that maya cannot remove a namespace that // is not empty. // // namespace -removeNamespace ":RM_TEST_ROOT:FOO"; // Run this command you'll get an error. // Trying to remove an empty namespace. // Namespace :RM_TEST_ROOT:FOO:BAR:JOE has been removed successfully by the command. // namespace -removeNamespace ":RM_TEST_ROOT:FOO:BAR:JOE"; undo; // Recover namespace structure. // Usage of -deleteNamespaceContent flag: // Remove all the contents in the target namespace specified in the command and // remove the namespace namespace -deleteNamespaceContent -removeNamespace ":RM_TEST_ROOT:FOO:BAR"; undo; // Recover namespace structure. // Usage of -mergeNamespaceWithParent flag: // Move the content of the target namespace specified in the command to its parent // namespace and remove the namespace. namespace -mergeNamespaceWithParent -removeNamespace ":RM_TEST_ROOT:FOO:BAR"; undo; // Recover namespace structure. // Usage of -mergeNamespaceWithRoot flag: // Move the content of the target namespace specified in the command to the root // namespace and remove the namespace. namespace -mergeNamespaceWithRoot -removeNamespace ":RM_TEST_ROOT:FOO:BAR";