Python API 2.0 Reference
OpenMaya.MNamespace Class Reference
+ Inheritance diagram for OpenMaya.MNamespace:

Static Public Member Functions

def addNamespace ()
 
def currentNamespace ()
 
def getNamespaceFromName ()
 
def getNamespaceObjects ()
 
def getNamespaces ()
 
def makeNamepathAbsolute ()
 
def moveNamespace ()
 
def namespaceExists ()
 
def parentNamespace ()
 
def relativeNames ()
 
def removeNamespace ()
 
def renameNamespace ()
 
def rootNamespace ()
 
def setCurrentNamespace ()
 
def setRelativeNames ()
 
def stripNamespaceFromName ()
 
def validateName ()
 

Detailed Description

Access Maya namespace functionality.

Member Function Documentation

def OpenMaya.MNamespace.addNamespace ( )
static
addNamespace(MString name, MString parent=None)

Create the namespace 'name'. If the `parent' namespace is given
the new namespace will be a child of `parent', otherwise the new
namespace will be a child of the current namespace.
The new namespace is added, but not made current. To make the
new namespace be current use MNamespace.setCurrentNamespace().
Note that adding a namespace changes the scene, so any code that calls
this method needs to handle undo.  

     name    The new namespace to create. A qualified or unqualified 
 name may be used. If a qualified name is used and one or 
 more of the higher level namespaces do not already exist, 
 they will be created automatically. For example, if the new 
 name is 'a:b:c' and 'a' does not yet exist, then it will be 
 created automatically and 'b' automatically created beneath 
 it and finally 'c' will be created beneath 'b'.
 If the supplied name contains invalid characters it will first 
 be modified as per the validateName() method.
     parent  The fully qualified name of the namespace under which 
 the new one is to be created. If not provided then the 
 current namespace will be used. If the name of the new 
 namespace is absolute (i.e. begins with a colon, ':a:b:c') 
 then the 'parent' parameter will be ignored and the new namespace 
 will be created under the root namespace.
def OpenMaya.MNamespace.currentNamespace ( )
static
currentNamespace() -> MString

Get the name of the current namespace. This name is returned 
as an absolute namepath (i.e. fully qualfied from the root 
namespace downwards, ':a:b:c').
def OpenMaya.MNamespace.getNamespaceFromName ( )
static
getNamespaceFromName(MString fullName) -> MString

Get namespace from a full name. 
For example, given a full name: 'a:b:c:d:ball' this method 
would return: 'a:b:c:d'.
def OpenMaya.MNamespace.getNamespaceObjects ( )
static
getNamespaceObjects(MString parentNamespace, bool recurse=False) -> MObjectArray

Return an array of MObjects representing the object contained within 
the specified namespace. To query the current namespace, call this 
method in this way:
def OpenMaya.MNamespace.getNamespaces ( )
static
getNamespaces(MString parentNamespace=None, bool recurse=False) -> [MString]

Return a list of all namespaces in the current namespace.
Notes:
    1)  Names returned are always absolute (e.g. :a:b:sphere).
    2)  The list returned is just the child namespaces (and
        descendents if `recurse' is true). It thus never contains
        the root namespace in the list returned.

           parentNamespace  the namespace to query.
           recurse          optional parameter to control whether all
                namespaces or just top-level namespaces
                are returned. A value of false (the
                default if unspecified) causes only the
                top-level namespaces to be returned. If
                true, all namespaces will be listed.
def OpenMaya.MNamespace.makeNamepathAbsolute ( )
static
makeNamepathAbsolute(MString fullName) -> MString

Make a namepath which is relative to the root into an absolute 
namepath. For example, given the namepath 'a:sphere' this method 
returns ':a:sphere'. It also culls out duplicate and trailing 
separators, e.g. 'a:b::c:' will return ':a:b:c'.
def OpenMaya.MNamespace.moveNamespace ( )
static
moveNamespace(MString src, MString dst, bool force=False)

Move the contents of the namespace 'src' into the namespace 'dst'. 
Note that moving namespace contents changes the scene, so any code 
that calls this method needs to handle undo. 

          src       source namespace from which objects will be moved. 
          dst       destination namespace to which objects will be moved. 
          force     optional parameter which if true forces the move 
        even if name clashes occur, in which case nodes are 
        renamed to ensure uniqueness. If false, the move 
        will not happen if there are clashes. The default 
        value is false.
def OpenMaya.MNamespace.namespaceExists ( )
static
namespaceExists(MString name) -> bool

Check if a given namespace exists.
def OpenMaya.MNamespace.parentNamespace ( )
static
parentNamespace() -> MString

Get the name of the current namespace's parent. This name is returned 
as an absolute namepath (i.e. fully qualfied from the root namespace 
downwards, ':a:b'). If the root namespace is 
current, this method returns an error.
def OpenMaya.MNamespace.relativeNames ( )
static
relativeNames() -> bool

Query Maya's current 'relative name lookup' state. Relative name 
lookup causes lookups to be relative to the current namespace. 
By default, relative name lookup in Maya is off, which causes 
name lookups to be relative to the root namespace. For example, 
if you have the object :a:b:sphere, and the current namespace is 
':a:b', in relative name lookup mode you can issue a command like 

    setAttr sphere.translateX 10; 

If relative name lookup is off, you need to specify the full 
namepath, e.g. 

    setAttr a:b:sphere.translateX 10;
def OpenMaya.MNamespace.removeNamespace ( )
static
removeNamespace(MString name, bool removeContents=False)

Remove the specified namespace. 
Note that removing a namespace changes the scene, so any code 
that calls this method needs to handle undo.
def OpenMaya.MNamespace.renameNamespace ( )
static
renameNamespace(MString oldName, MString newName, MString parent=None)

Rename the specified namespace to a new name with optional parent name. 
Note that removing a namespace changes the scene, so any code 
that calls this method needs to handle undo.
def OpenMaya.MNamespace.rootNamespace ( )
static
rootNamespace() -> MString

Get the name of the root namespace. This name is an absolute
namepath (i.e. prefixed by a ':').
def OpenMaya.MNamespace.setCurrentNamespace ( )
static
setCurrentNamespace(MString name) -> MString

Set the specified namespace to be the current namespace. The 'name' 
parameter you specify is relative to whatever namespace is current, 
but any namespace can be specified by passing an absolute name (e.g. :a:b:c).  
Note that making a namespace current changes the scene, so any code 
that calls this method needs to handle undo. 

To make the root namespace become current, use:
    MNamespace.setCurrentNamespace(MNamespace.rootNamespace())
def OpenMaya.MNamespace.setRelativeNames ( )
static
setRelativeNames(bool newState)

Set relative name lookup mode. 

Note that turning on or off relativeNames mode can change the scene, 
so any code that calls this method needs to handle undo. 
See MNamespace.relativeNames() for details on relative name lookup. 

Note: relative name lookup mode is intended for bracketing user 
code which needs to be namespace-independent. Leaving relative 
name lookup enabled outside of your specific code could cause 
functionality such as 3rd-party plugins that assume absolute 
name lookup to fail. 

   newState         true to turn on relative name lookup, false to 
        turn it off. Maya's default setting is false.
def OpenMaya.MNamespace.stripNamespaceFromName ( )
static
stripNamespaceFromName(MString fullName) -> MString

Strips the namespace from a full name. 
For example, given a full name: 'a:b:c:d:ball' this method  
would return: 'ball'.
def OpenMaya.MNamespace.validateName ( )
static
validateName(MString name) -> MString

Convert the specified name to a validated name which 
contains no illegal characters.
The leading illegal characters will be removed and
other illegal characters will be converted to '_'.

For example, name '@name@space@' will be converted to 'name_space_'.

If the entire name consists solely of illegal characters, 
e.g. '123' which contains only leading digits, then the 
returned string will be empty.