Python API 2.0 Reference
|
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 () |
Access Maya namespace functionality.
|
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.
|
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').
|
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'.
|
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:
|
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.
|
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'.
|
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.
|
static |
namespaceExists(MString name) -> bool Check if a given namespace exists.
|
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.
|
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;
|
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.
|
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.
|
static |
rootNamespace() -> MString Get the name of the root namespace. This name is an absolute namepath (i.e. prefixed by a ':').
|
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())
|
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.
|
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'.
|
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.