mrv.maya.ns

Epydoc: mrv.maya.ns

Allows convenient access and handling of namespaces in an object oriented manner

Functions

mrv.maya.ns._isRootOf(root, other)
Returns:

True if other which may be a string, is rooted at ‘root

Parameters:
  • other – ‘’ = root namespace’ hello:world => :hello:world
  • root – may be namespace or string. It must not have a ‘:’ in front, hence it must be a relative naespace, and must end with a ‘:’.
Note:

the arguments are very specific, but this allows the method to be faster than usual

mrv.maya.ns.createNamespace(*args)
see Namespace.create
mrv.maya.ns.currentNamespace()
see Namespace.current
mrv.maya.ns.existsNamespace(namespace)
:return : True if given namespace ( name ) exists
mrv.maya.ns.findUniqueNamespace(*args, **kwargs)
see Namespace.findUnique
mrv.maya.ns.noneToList(res)
Returns:list instead of None

Classes

Epydoc: mrv.maya.ns

class mrv.maya.ns.CallOnDeletion(callableobj)

Bases: object

Call the given callable object once this object is being deleted Its usefull if you want to assure certain code to run once the parent scope of this object looses focus

callableobj

Epydoc: mrv.maya.ns.Namespace

class mrv.maya.ns.Namespace

Bases: unicode, mrv.interface.iDagItem

Represents a Maya namespace Namespaces follow the given nameing conventions:

  • Paths starting with a column are absolute
  • :absolute:path
  • Path separator is ‘:’
classmethod addSep(item, sep)
Returns:

item with separator added to it ( just once )

Note:

operates best on strings

Parameters:
  • item – item to add separator to
  • sep – the separator
basename()
Returns:basename of this path, ‘/hello/world’ -> ‘world’
capitalize

S.capitalize() -> unicode

Return a capitalized version of S, i.e. make the first character have upper case.

center

S.center(width[, fillchar]) -> unicode

Return S centered in a Unicode string of length width. Padding is done using the specified fill character (default is a space)

children(predicate=<function <lambda> at 0x5c445f0>)
Returns:list of child namespaces
Parameter:predicate – return True to include x in result
childrenDeep(order=1, predicate=<function <lambda> at 0x7f41dd7c5050>)
Returns:

list of all children of path, [ child1 , child2 ]

Parameters:
  • order – order enumeration
  • predicate – returns true if x may be returned
Note:

the child objects returned are supposed to be valid paths, not just relative paths

count

S.count(sub[, start[, end]]) -> int

Return the number of non-overlapping occurrences of substring sub in Unicode string S[start:end]. Optional arguments start and end are interpreted as in slice notation.

classmethod create(*args, **kwargs)

Create a new namespace

Parameter: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
Note:if the target namespace already exists, it will be returned
Returns:the create Namespace object
classmethod current()
Returns:the currently set absolute namespace
decode

S.decode([encoding[,errors]]) -> string or unicode

Decodes S using the codec registered for encoding. encoding defaults to the default encoding. errors may be given to set a different error handling scheme. Default is ‘strict’ meaning that encoding errors raise a UnicodeDecodeError. Other possible values are ‘ignore’ and ‘replace’ as well as any other name registerd with codecs.register_error that is able to handle UnicodeDecodeErrors.

defaultIncrFunc(b, i)
%s%02i
delete(move_to_namespace=':', autocreate=True)

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
Note:

can handle sub-namespaces properly

Raises RuntimeError:
 
Todo:

Implement undo !

encode

S.encode([encoding[,errors]]) -> string or unicode

Encodes S using the codec registered for encoding. encoding defaults to the default encoding. errors may be given to set a different error handling scheme. Default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.

endswith

S.endswith(suffix[, start[, end]]) -> bool

Return True if S ends with the specified suffix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. suffix can also be a tuple of strings to try.

exists()
Returns:True if this namespace exists
expandtabs

S.expandtabs([tabsize]) -> unicode

Return a copy of S where all tab characters are expanded using spaces. If tabsize is not given, a tab size of 8 characters is assumed.

find

S.find(sub [,start [,end]]) -> int

Return the lowest index in S where substring sub is found, such that sub is contained within s[start:end]. Optional arguments start and end are interpreted as in slice notation.

Return -1 on failure.

classmethod findUnique(basename, incrementFunc=<function <lambda> at 0x5c3e488>)

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

format
S.format(*args, **kwargs) -> unicode
fullChildName(childname)
Add the given name to the string version of our instance :return: string with childname added like name _sep childname
index

S.index(sub [,start [,end]]) -> int

Like S.find() but raise ValueError when the substring is not found.

isAbsolute()
Returns:True if this namespace is an absolut one, defining a namespace from the root namespace like “:foo:bar
isPartOf(other)
Returns:True if self is a part of other, and thus can be found in other
Note:operates on strings only
isRoot()
Returns:True if this path is the root of the DAG
isRootOf(other)
Returns:True other starts with self
Note:operates on strings
Note:we assume other has the same type as self, thus the same separator
isalnum

S.isalnum() -> bool

Return True if all characters in S are alphanumeric and there is at least one character in S, False otherwise.

isalpha

S.isalpha() -> bool

Return True if all characters in S are alphabetic and there is at least one character in S, False otherwise.

isdecimal

S.isdecimal() -> bool

Return True if there are only decimal characters in S, False otherwise.

isdigit

S.isdigit() -> bool

Return True if all characters in S are digits and there is at least one character in S, False otherwise.

islower

S.islower() -> bool

Return True if all cased characters in S are lowercase and there is at least one cased character in S, False otherwise.

isnumeric

S.isnumeric() -> bool

Return True if there are only numeric characters in S, False otherwise.

isspace

S.isspace() -> bool

Return True if all characters in S are whitespace and there is at least one character in S, False otherwise.

istitle

S.istitle() -> bool

Return True if S is a titlecased string and there is at least one character in S, i.e. upper- and titlecase characters may only follow uncased characters and lowercase characters only cased ones. Return False otherwise.

isupper

S.isupper() -> bool

Return True if all cased characters in S are uppercase and there is at least one cased character in S, False otherwise.

iterNodes(*args, **kwargs)

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

iterParents(predicate=<function <lambda> at 0x7f41dd7c5230>)
Returns:generator retrieving all parents up to the root
Parameter:predicate – returns True for all x that you want to be returned
join

S.join(iterable) -> unicode

Return a string which is the concatenation of the strings in the iterable. The separator between elements is S.

ljust

S.ljust(width[, fillchar]) -> int

Return S left-justified in a Unicode string of length width. Padding is done using the specified fill character (default is a space).

lower

S.lower() -> unicode

Return a copy of the string S converted to lowercase.

lstrip

S.lstrip([chars]) -> unicode

Return a copy of the string S with leading whitespace removed. If chars is given and not None, remove characters in chars instead. If chars is a str, it will be converted to unicode before stripping

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

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
Todo:

Implement undo !

parent()
Returns:parent namespace of this instance
parentDeep()
Returns:all parents of this path, ‘/hello/my/world’ -> [ ‘/hello/my’,’/hello’ ]
partition

S.partition(sep) -> (head, sep, tail)

Search for the separator sep in S, and return the part before it, the separator itself, and the part after it. If the separator is not found, return S and two empty strings.

relativeTo(basenamespace)

returns this namespace relative to the given basenamespace

Parameter:basenamespace – the namespace to which the returned one should be relative too
Raises ValueError:
 If this or basenamespace is not absolute or if no relative namespace exists
Returns:relative namespace
rename(newName)

Rename this namespace to newName - the original namespace will cease to exist

Note:if the namespace already exists, the existing one will be returned with all objects from this one added accordingly
Parameter:newName – the absolute name of the new namespace
Returns:Namespace with the new name
Todo:Implement undo !
replace

S.replace (old, new[, count]) -> unicode

Return a copy of S with all occurrences of substring old replaced by new. If the optional argument count is given, only the first count occurrences are replaced.

rfind

S.rfind(sub [,start [,end]]) -> int

Return the highest index in S where substring sub is found, such that sub is contained within s[start:end]. Optional arguments start and end are interpreted as in slice notation.

Return -1 on failure.

rindex

S.rindex(sub [,start [,end]]) -> int

Like S.rfind() but raise ValueError when the substring is not found.

rjust

S.rjust(width[, fillchar]) -> unicode

Return S right-justified in a Unicode string of length width. Padding is done using the specified fill character (default is a space).

root()
Returns:the root of the DAG - it has no further parents
rpartition

S.rpartition(sep) -> (head, sep, tail)

Search for the separator sep in S, starting at the end of S, and return the part before it, the separator itself, and the part after it. If the separator is not found, return two empty strings and S.

rsplit

S.rsplit([sep [,maxsplit]]) -> list of strings

Return a list of the words in S, using sep as the delimiter string, starting at the end of the string and working to the front. If maxsplit is given, at most maxsplit splits are done. If sep is not specified, any whitespace string is a separator.

rstrip

S.rstrip([chars]) -> unicode

Return a copy of the string S with trailing whitespace removed. If chars is given and not None, remove characters in chars instead. If chars is a str, it will be converted to unicode before stripping

setCurrent(*args, **kwargs)

Set this namespace to be the current one - new objects will be put in it by default

Returns:self
split

S.split([sep [,maxsplit]]) -> list of strings

Return a list of the words in S, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done. If sep is not specified or is None, any whitespace string is a separator and empty strings are removed from the result.

classmethod splitNamespace(objectname)

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
splitlines

S.splitlines([keepends]) -> list of strings

Return a list of the lines in S, breaking at line boundaries. Line breaks are not included in the resulting list unless keepends is given and true.

startswith

S.startswith(prefix[, start[, end]]) -> bool

Return True if S starts with the specified prefix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. prefix can also be a tuple of strings to try.

strip

S.strip([chars]) -> unicode

Return a copy of the string S with leading and trailing whitespace removed. If chars is given and not None, remove characters in chars instead. If chars is a str, it will be converted to unicode before stripping

substitute(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
Note:if replacement is an empty string, it will effectively cut the matched namespace off the object name
Note:handles replacement of subnamespaces correctly as well
Note:as it operates on strings, the actual namespaces do not need to exist
classmethod substituteNamespace(thisns, find_in, replacement)
Same as substitute, but signature might feel more natural
supports(interface_type)
Returns:True if this instance supports the interface of the given type
Parameter:interface_type – Type of the interface you require this instance to support
Note:Must be used in case you only have a weak reference of your interface instance or proxy which is a case where the ordinary isinstance( obj, iInterface ) will not work
swapcase

S.swapcase() -> unicode

Return a copy of S with uppercase characters converted to lowercase and vice versa.

title

S.title() -> unicode

Return a titlecased version of S, i.e. words start with title case characters, all remaining cased characters have lower case.

toRelative()
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
translate

S.translate(table) -> unicode

Return a copy of the string S, where all characters have been mapped through the given translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, Unicode strings or None. Unmapped characters are left untouched. Characters mapped to None are deleted.

upper

S.upper() -> unicode

Return a copy of S converted to uppercase.

zfill

S.zfill(width) -> unicode

Pad a numeric string S with zeros on the left, to fill a field of the specified width. The string S is never truncated.

Epydoc: mrv.maya.ns

class mrv.maya.ns.iDagItem

Bases: mrv.interface.Interface

Describes interface for a DAG item. Its used to unify interfaces allowing to access objects in a dag like graph Of the underlying object has a string representation, the defatult implementation will work natively. Otherwise the getParent and getChildren methods should be overwritten

Note:a few methods of this class are abstract and need to be overwritten
Note:this class expects the attribute ‘_sep’ to exist containing the separator at which your object should be split ( for default implementations ). This works as the passed in pointer will belong to derived classes that can define that attribute on instance or on class level
classmethod addSep(item, sep)
Returns:

item with separator added to it ( just once )

Note:

operates best on strings

Parameters:
  • item – item to add separator to
  • sep – the separator
basename()
Returns:basename of this path, ‘/hello/world’ -> ‘world’
children(predicate=<function <lambda> at 0x7f41dd7c2ed8>)
Returns:list of intermediate children of path, [ child1 , child2 ]
Parameter:predicate – return True to include x in result
Note:the child objects returned are supposed to be valid paths, not just relative paths
childrenDeep(order=1, predicate=<function <lambda> at 0x7f41dd7c5050>)
Returns:

list of all children of path, [ child1 , child2 ]

Parameters:
  • order – order enumeration
  • predicate – returns true if x may be returned
Note:

the child objects returned are supposed to be valid paths, not just relative paths

fullChildName(childname)
Add the given name to the string version of our instance :return: string with childname added like name _sep childname
isPartOf(other)
Returns:True if self is a part of other, and thus can be found in other
Note:operates on strings only
isRoot()
Returns:True if this path is the root of the DAG
isRootOf(other)
Returns:True other starts with self
Note:operates on strings
Note:we assume other has the same type as self, thus the same separator
iterParents(predicate=<function <lambda> at 0x7f41dd7c5230>)
Returns:generator retrieving all parents up to the root
Parameter:predicate – returns True for all x that you want to be returned
parent()
Returns:parent of this path, ‘/hello/world’ -> ‘/hello’ or None if this path is the dag’s root
parentDeep()
Returns:all parents of this path, ‘/hello/my/world’ -> [ ‘/hello/my’,’/hello’ ]
root()
Returns:the root of the DAG - it has no further parents
supports(interface_type)
Returns:True if this instance supports the interface of the given type
Parameter:interface_type – Type of the interface you require this instance to support
Note:Must be used in case you only have a weak reference of your interface instance or proxy which is a case where the ordinary isinstance( obj, iInterface ) will not work

Table Of Contents

Previous topic

mrv.maya.all

Next topic

mrv.maya.scene

This Page