Package mrv :: Package maya :: Module ns :: Class Namespace
[hide private]
[frames] | no frames]

Class Namespace

source code

         object --+        
                  |        
         basestring --+    
                      |    
                unicode --+
                          |
         object --+       |
                  |       |
interface.Interface --+   |
                      |   |
     interface.iDagItem --+
                          |
                         Namespace

Represents a Maya namespace Namespaces follow the given nameing conventions:

Instance Methods [hide private]

Inherited from unicode: __contains__, __eq__, __format__, __ge__, __getattribute__, __getitem__, __getnewargs__, __getslice__, __gt__, __hash__, __le__, __len__, __lt__, __mod__, __mul__, __ne__, __rmod__, __rmul__, __sizeof__, __str__, capitalize, center, count, decode, encode, endswith, expandtabs, find, format, index, isalnum, isalpha, isdecimal, isdigit, islower, isnumeric, isspace, istitle, isupper, join, ljust, lower, lstrip, partition, replace, rfind, rindex, rjust, rpartition, rsplit, rstrip, split, splitlines, startswith, strip, swapcase, title, translate, upper, zfill

Inherited from unicode (private): _formatter_field_name_split, _formatter_parser

Inherited from interface.Interface: supports

Inherited from object: __delattr__, __init__, __reduce__, __reduce_ex__, __setattr__, __subclasshook__

    Overridden Methods
a new object with type S, a subtype of T
__new__(cls, namespacepath=rootpath, absolute=True)
Initialize the namespace with the given namespace path
source code
 
__add__(self, other)
Properly catenate namespace objects - other must be relative namespace or object name ( with or without namespace )
source code
 
__repr__(self)
repr(x)
source code
    Edit Methods
 
rename(self, newName)
Rename this namespace to newName - the original namespace will cease to exist
source code
 
moveNodes(self, targetNamespace, force=True, autocreate=True)
Move objects from this to the targetNamespace
source code
 
delete(self, move_to_namespace=rootpath, autocreate=True)
Delete this namespace and move it's obejcts to the given move_to_namespace
source code
 
setCurrent(self)
Set this namespace to be the current one - new objects will be put in it by default
source code
    Query Methods
 
parent(self)
Returns: parent namespace of this instance
source code
 
children(self, predicate=lambda x: True)
Returns: list of child namespaces
source code
 
exists(self)
Returns: True if this namespace exists
source code
 
isAbsolute(self)
Returns: True if this namespace is an absolut one, defining a namespace from the root namespace like ":foo:bar
source code
 
toRelative(self)
Returns: a relative version of self, thus it does not start with a colon
source code
 
relativeTo(self, basenamespace)
returns this namespace relative to the given basenamespace
source code
 
_removeDuplicateSep(self, name)
Returns: name with duplicated : removed
source code
 
substitute(self, find_in, replacement)
Returns: string with our namespace properly substituted with replacement such that the result is a properly formatted object name ( with or without namespace depending of the value of replacement ) As this method is based on string replacement, self might as well match sub-namespaces if it is relative
source code

Inherited from interface.iDagItem: basename, childrenDeep, isPartOf, isRoot, isRootOf, parentDeep, root

    Object Retrieval
 
iterNodes(self, *args, **kwargs)
Return an iterator on all objects in the namespace
source code
    Iterators

Inherited from interface.iDagItem: iterParents

    Name Generation

Inherited from interface.iDagItem: fullChildName

Class Methods [hide private]
    Edit Methods
 
create(cls, namespaceName)
Create a new namespace
source code
    Query Methods
 
current(cls)
Returns: the currently set absolute namespace
source code
 
findUnique(cls, basename, incrementFunc=defaultIncrFunc)
Find a unique namespace based on basename which does not yet exist in the scene and can be created.
source code
 
splitNamespace(cls, objectname)
Cut the namespace from the given name and return a tuple( namespacename, objectname )
source code
 
substituteNamespace(cls, thisns, find_in, replacement)
Same as substitute, but signature might feel more natural
source code
    Name Generation

Inherited from interface.iDagItem: addSep

Class Variables [hide private]
  re_find_duplicate_sep = re.compile(":{2,}")
  rootpath = ':'
  _defaultns = ['UI', 'shared']
  defaultIncrFunc = lambda b, i:

Inherited from interface.iDagItem: kOrder_BreadthFirst, kOrder_DepthFirst

    Configuration
  _sep = ':'
hash(x)
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__new__(cls, namespacepath=rootpath, absolute=True)

source code 
Initialize the namespace with the given namespace path
Parameters:
  • namespacepath - the namespace to wrap - it should be absolut to assure relative namespaces will not be interpreted in an unforseen manner ( as they are relative to the currently set namespace

    Set it ":" ( or "" ) to describe the root namespace

  • absolute - if True, incoming namespace names will be made absolute if not yet the case
Returns: a new object with type S, a subtype of T
Overrides: object.__new__

Note: the namespace does not need to exist, but many methods will not work if so. NamespaceObjects returned by methods of this class are garantueed to exist

__add__(self, other)
(Addition operator)

source code 
Properly catenate namespace objects - other must be relative namespace or object name ( with or without namespace )
Returns:
new string object
Overrides: unicode.__add__

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

create(cls, namespaceName)
Class Method

source code 
Create a new namespace
Parameters:
  • namespaceName - the name of the namespace, absolute or relative - it may contain subspaces too, i.e. :foo:bar. fred:subfred is a relative namespace, created in the currently active namespace
Returns:
the create Namespace object
Decorators:
  • @undo.undoable

Note: if the target namespace already exists, it will be returned

rename(self, newName)

source code 
Rename this namespace to newName - the original namespace will cease to exist
Parameters:
  • newName - the absolute name of the new namespace
Returns:
Namespace with the new name

Note: if the namespace already exists, the existing one will be returned with all objects from this one added accordingly

To Do: Implement undo !

moveNodes(self, targetNamespace, force=True, autocreate=True)

source code 
Move objects from this to the targetNamespace
Parameters:
  • force - if True, namespace clashes will be resolved by renaming, if false possible clashes would result in an error
  • autocreate - if True, targetNamespace will be created if it does not exist yet

To Do: Implement undo !

delete(self, move_to_namespace=rootpath, autocreate=True)

source code 
Delete this namespace and move it's obejcts to the given move_to_namespace
Parameters:
  • move_to_namespace - if None, the namespace to be deleted must be empty If Namespace, objects in this namespace will be moved there prior to namespace deletion move_to_namespace must exist
  • autocreate - if True, move_to_namespace will be created if it does not exist yet
Raises:
  • RuntimeError

Note: can handle sub-namespaces properly

To Do: Implement undo !

setCurrent(self)

source code 
Set this namespace to be the current one - new objects will be put in it by default
Returns:
self
Decorators:
  • @undo.undoable

parent(self)

source code 
Returns:
parent namespace of this instance
Overrides: interface.iDagItem.parent

children(self, predicate=lambda x: True)

source code 
Parameters:
  • predicate - return True to include x in result
Returns:
list of child namespaces
Overrides: interface.iDagItem.children

current(cls)
Class Method

source code 
Returns:
the currently set absolute namespace

findUnique(cls, basename, incrementFunc=defaultIncrFunc)
Class Method

source code 
Find a unique namespace based on basename which does not yet exist in the scene and can be created.
Parameters:
  • basename - basename of the namespace, like ":mynamespace" or "mynamespace:subspace"
  • incrementFunc - func( basename, index ), returns a unique name generated from the basename and the index representing the current iteration
Returns:
unique namespace that is guaranteed not to exist below the current namespace

exists(self)

source code 
Returns:
True if this namespace exists

isAbsolute(self)

source code 
Returns:
True if this namespace is an absolut one, defining a namespace from the root namespace like ":foo:bar

toRelative(self)

source code 
Returns:
a relative version of self, thus it does not start with a colon

Note: the root namespace cannot be relative - if this is of interest for you, you have to check for it. This method gracefully ignores that fact to make it more convenient to use as one does not have to be afraid of exceptions

relativeTo(self, basenamespace)

source code 
returns this namespace relative to the given basenamespace
Parameters:
  • basenamespace - the namespace to which the returned one should be relative too
Returns:
relative namespace
Raises:
  • ValueError - If this or basenamespace is not absolute or if no relative namespace exists

splitNamespace(cls, objectname)
Class Method

source code 
Cut the namespace from the given name and return a tuple( namespacename, objectname )

Note: method assumes that the namespace starts at the beginning of the object

_removeDuplicateSep(self, name)

source code 
Returns:
name with duplicated : removed

substitute(self, find_in, replacement)

source code 
Returns:
string with our namespace properly substituted with replacement such that the result is a properly formatted object name ( with or without namespace depending of the value of replacement ) As this method is based on string replacement, self might as well match sub-namespaces if it is relative
Notes:
  • if replacement is an empty string, it will effectively cut the matched namespace off the object name
  • handles replacement of subnamespaces correctly as well
  • as it operates on strings, the actual namespaces do not need to exist

iterNodes(self, *args, **kwargs)

source code 
Return an iterator on all objects in the namespace
Parameters:
  • args - MFn.kType filter types to be used to pre-filter the nodes in the namespace. This can greatly improve performance !
  • kwargs - given to iterDagNodes or iterDgNodes, which includes the option to provide a predicate function. Additionally, the following ones may be defined:

    • asNode:

      if true, default True, Nodes will be yielded. If False, you will receive MDagPaths or MObjects depending on the 'dag' kwarg

    • dag:

      if True, default False, only dag nodes will be returned, otherwise you will receive dag nodes and dg nodes. Instance information will be lost on the way though.

    • depth:

      if 0, default 0, only objects in this namespace will be returned

      if -1, all subnamespaces will be included as well, the depth is unlimited

      if 0<depth<x include all objects up to the 'depth' subnamespace

Note: this method is quite similar to FileReference.iterNodes, but has a different feature set and needs this code here for maximum performance