MNode

class MNode(node=None, node_type=None, name=None)

Bases: OpenMaya.MObject

Purpose:
Provides object oriented interface for querying/editing DAG or DG nodes inside Maya.

An instance of the MNode class provides storage and access to a single

Maya node. Methods within the class replace the most commonly use maya commands. Public methods operate on the object stored within the MNode. Note that most methods support the same keywords arguments as their maya.cmds equivalent.

Extends:

OpenMaya.MObject

Methods Summary

addAttr([long_name, attr_type]) Adds an attribute of the given long name and given type to the node.
addMenuCmd(ui_name, cmd_str) Add a context sensitive making menu to this node.
applyAttrMap(attr_map[, skip_missing, …]) Apply the attribute values in the given dictionary object to this node.
attachMenuItems(parent_menu) This method attaches any defined menu cmds on this node to the given Maya menu item.
attributeQuery(attr_name, **kargs) Query information about the given attribute.
bakeResults(*args, **kargs) Run bakeResults on this node with the given options
capitalize([include_namespaces]) String operartion just like str.capitalize().
connectAttr(src_attr, dst_node, dst_attr, …) Connects the given attribute of this node to the given node and attribute.
count(sub[, start, end, include_namespaces]) String operartion just like str.count().
createNode([node_type]) Wrapper class method for maya.cmds.createNode thats returns a MNode object instead of a string name
delete() Delete the node from the scene.
deleteAttr(attr_name) Delete the attr with the given name from this node.
duplicate(**kargs) Duplicate the node with the given options
endswith(suffix[, start, end, …]) String operartion just like str.endswith().
find(sub[, start, end, include_namespaces]) String operartion just like str.find().
getAddAttrCmd(attr_name[, use_long_names]) Returns a string containing mel addAttr command for re-creating given dynamic attribute.
getAddAttrMaps() Returns a dictionary that contains addAttr details for all user defined dynamic attributes on the current node.
getAttr(attr_name, **kargs) Returns the value of the given attr on this node.
getAttrMap(*args, **kargs) Returns an OrderedDict of attributes as keys and their values as values.
getBasename() Returns the string name of this node any namespaces.
getHashCode() Returns a hash code for the internal Maya object referenced by the MObject within this MNode
getInheritedNodeTypes() Returns the node classes that this node type is inherited from.
getMObject() Returns the MObject of this node
getMObjectHandle() Returns the MObjectHandle of this node
getMenuCmds() Return all custom marking menu items on this node.
getMessageAttr(attr_name) Returns the node that is connected to the given message attribute.
getName() Returns the string name of this node.
getNamespace() Return the namespace this node belongs to, if any.
getNextAttr(attr_prefix[, start_num, max_search]) Finds the next available attribute that is available with the given prefix.
getObjectType() Returns the string node type of this node.
getPath() Returns the full path name of this node.
getPluginName() Return the name of the plugin that defines this node, if any
getPlugs() Returns the string names of all attributes that have incoming connections.
getSetAttrCmds(attr_name[, long_names, …]) Returns an tuple of strings containing mel setAttr commands for given attribute and all of its descendent attrs.
hasAttr(attr_name[, parent_attr]) Returns whether this node has an attribute with the given name.
hasUniqueName() Indicates whether or not this node’s name is unique within the scene.
index(sub[, start, end, include_namespaces]) String operartion just like str.index().
isFromReferencedFile() Indicates whether or not this node came from a referenced file.
isLocked() Indicates whether or not this node is locked.
isValid() Tests whether this node is still valid.
isalnum([include_namespaces]) String operartion just like str.isalnum().
isalpha([include_namespaces]) String operartion just like str.isalpha().
islower([include_namespaces]) String operartion just like str.islower().
istitle([include_namespaces]) String operartion just like str.istitle().
isupper([include_namespaces]) String operartion just like str.isupper().
join(iterable[, include_namespaces]) String operartion just like str.join().
listAttr(*args, **kargs) List the atributes on this node
listConnections([attr_name]) List connections to this node
lower([include_namespaces]) String operartion just like str.lower().
ls(*args, **kargs) Wrapper class method for maya.cmds.ls thats returns a MNodeList result instead of a list of string names
lstrip([chars, include_namespaces]) String operartion just like str.lstrip().
partition(sep[, include_namespaces]) String operartion just like str.partition().
removeInputConnections(attr_name) Remove any incoming connections to the attribute with the given name.
removeOutputConnections(attr_name) Remove any output connections from the attribute with the given name.
rename(new_name, **kargs) Rename this node
replace(old, new[, count, include_namespaces]) String operartion just like str.replace().
rfind(sub[, start, end, include_namespaces]) String operartion just like str.rfind().
rindex(sub[, start, end, include_namespaces]) String operartion just like str.rindex().
rpartition(sep[, include_namespaces]) String operartion just like str.rpartition().
rsplit(sep[, maxsplit, include_namespaces]) String operartion just like str.rsplit().
rstrip([chars, include_namespaces]) String operartion just like str.lstrip().
select(**kargs) Selects this node with the given options.
setAttr(attr_name, *args, **kargs) Sets the given attr to the given value
setAttrsFromMap(attr_map[, skip_missing]) Set attribute values from a dictionary object that has attribute names as keys and attribute values as values
setDrivenKeyframe(attr, driver, driver_attr, …) Sets a set driven key on the current node using the given options
setMessageAttr(attr_name, node[, lock]) Connects the given node to the given message attribute on this node.
setStringAttr(attr_name, val, **kargs) Sets the given value on the given string attr.
split(sep[, maxsplit, include_namespaces]) String operartion just like str.split().
startswith(prefix[, start, end, …]) String operartion just like str.startswith().
strip([chars, include_namespaces]) String operartion just like str.strip().
swapcase([include_namespaces]) String operartion just like str.swapcase().
upper([include_namespaces]) String operartion just like str.upper().

Methods Documentation

addAttr(long_name=None, attr_type=None, **kargs)

Adds an attribute of the given long name and given type to the node. Supports all keyword args of maya.cmds.addAttr except “dt” and “at” which are replaced by the attr_type arg.

long_name string long name of the attribute to add. This is optional if you prefer to use the
standard Maya longName and/or shortName keywaords instead.
attr_type string type of attribute to add. Supports all string types supported by
the “dt” and “at” args of maya.cmds.addAttr

kargs keyword args supported by maya.cmds.addAttr and keyword ‘channelBox’

RETURNS None

>>> node_1.addAttr("test", "float")
addMenuCmd(ui_name, cmd_str)

Add a context sensitive making menu to this node.

ui_name string menu item name to give this command in the marking menu

cmd string of python code to run when the menu item is selected

RETURNS None

applyAttrMap(attr_map, skip_missing=False, skip_errors=False)

Apply the attribute values in the given dictionary object to this node.

attr_map dictionary object with str attribute names as keys and attribute values as values

skip_missing bool - whether to skip over attributes that are missing from the scene. If False,
a missing attribute will raise a RuntimeError
skip_errors bool - whether to skip over setAttr errors. The default, False, will raise an exception
if a setAttr error occurs.

RETURNS None

>>> attr_map = {"translateX":100.0, "visibility":True}
>>> node.applyAttrMap(attr_map)
attachMenuItems(parent_menu)

This method attaches any defined menu cmds on this node to the given Maya menu item. Defined menu commands should be created using the addMenuCmd method.

This is designed to be used in Maya’s dagMenuProc.mel but can be used with any Maya menu item.

To get this to work with default dag marking menu, Maya’s dagMenuProc.mel must be modified with the following mel code at the top of global proc dagMenuProc() —

python("import mpylib; mpylib.MNode('" + $object + "').attachMenuItems('" + $parent + "')");

parent_menu string parent menu item to attach to

RETURNS None

attributeQuery(attr_name, **kargs)

Query information about the given attribute.

attr_name string name of the attribute to query

kargs keyword args supported by maya.cmds.attributeQuery

RETURNS results of the attribute query

>>> ## query the string values of an enum attr
>>> node.attributeQuery("myEnumAttr", listEnum=True)
>>>
>>> ## tset if the attr is an enum
>>> node.attributeQuery("myEnumAttr", enum=True)
bakeResults(*args, **kargs)

Run bakeResults on this node with the given options

args optional string args of attributes to bake. If args are given,
any value given to the attribute flag will be overridden

kargs keyword args supported by maya.cmds.bakeResults

RETURNS None

>>> node_1.bakeResults("translateX", "scaleY", simulate=True)
capitalize(include_namespaces=False)

String operartion just like str.capitalize(). Return a copy of the objects shortname with only its first character capitalized

include_namespaces bool - If False, returned string will not include namespaces. default=False

RETURNS string

connectAttr(src_attr, dst_node, dst_attr, **kargs)

Connects the given attribute of this node to the given node and attribute.

src_attr string name of the source attr on this node

dst_node string name or MNode of the destination node

dst_attr string name of the destination node

kargs keywords arg supported by maya.cmds.connectAttr

RETURNS None

>>> ## connect node_a translateX to node_b translateZ
>>> node_a.connectAttr("tx", node_b, "tz")
count(sub, start=None, end=None, include_namespaces=False)

String operartion just like str.count(). Return the number of (non-overlapping) occurrences of substring sub in string s[start:end].

sub string substring to find with the object’s shortname

start optional int start index

end optional int end index

include_namespaces bool - If False, namespaces in the object’s name will be ignored. default=False

RETURNS int index or int -1 is sub-string not found

classmethod createNode(node_type=None, **kargs)

Wrapper class method for maya.cmds.createNode thats returns a MNode object instead of a string name

Parameters:
node_type : str node type to create
kargs : dict

keyword args supported by maya.cmds.createNode

Returns:
*MNode* of newly created node

Examples

>>> new_node = MNode.createNode("transform", name="new_node")
>>> new_node = MNode.createNode("time")
delete()

Delete the node from the scene. Trying to access the node after running this method will raise a RuntimeError.

RETURNS None

>>> node.delete()
deleteAttr(attr_name)

Delete the attr with the given name from this node.

src_attr string name of the attr to delete

RETURNS None

>>> node.addAttr("foo", "float")
>>> node.deleteAttr("foo")
duplicate(**kargs)

Duplicate the node with the given options

kargs keywords arg supported by maya.cmds.duplicate

RETURNS MNode of the new node

>>> new_node = node.duplicate()
endswith(suffix, start=None, end=None, include_namespaces=False)

String operartion just like str.endswith().

Return True if the string ends with the specified suffix, otherwise return False. suffix can also be a tuple of suffixes to look for. With optional start, test beginning at that position. With optional end, stop comparing at that position. Operrates only on the node’s name itself and NOT it’s full path if DAG

suffix string or tuple of strings to test against

start optional int test beginning at position

end optional int stop comparing at position

include_namespaces optional bool to include namespace in the test (default=False)

RETURNS bool

>>> node = MNode("cool_node")
>>> node.endswith("_node")
>>> #RESULT - True
find(sub, start=None, end=None, include_namespaces=False)

String operartion just like str.find().

Return the lowest index in objects shortname where the substring sub is found such that sub is wholly contained in s[start:end]. Return -1 on failure

sub string substring to find with the object’s shortname

start optional int start index

end optional int end index

include_namespaces bool - If False, namespaces in the object’s name will be ignored. default=False

RETURNS int index or int -1 is sub-string not found

getAddAttrCmd(attr_name, use_long_names=False)

Returns a string containing mel addAttr command for re-creating given dynamic attribute. This string could be used in a mayaAscii like format.

attr_name string name of the dynamic attribute to query

long_names bool - whether to return cmds with long attribute names. default=False

RETURNS string mel addAttr commands like you would see in a mayaAscii file or None

>>> node = MNode.createNode("transform")
>>> node.addAttr("test", "float")
>>> node.getAddAttrCmd("test")
>>> #RESULT - ' addAttr -ci true -sn "test" -ln "test" -at "float";'
getAddAttrMaps()

Returns a dictionary that contains addAttr details for all user defined dynamic attributes on the current node.

RETURNS dict containing keywords: “long_name”, “short_name”, “attr_type”

getAttr(attr_name, **kargs)

Returns the value of the given attr on this node.

attr_name string name of attr kargs keywords arg supported by maya.cmds.getAttr

RETURNS value of the attribute

>>> tx_val = node.getAttr("translateX")
getAttrMap(*args, **kargs)

Returns an OrderedDict of attributes as keys and their values as values. This method supports all arguments and keyword arguments used by maya.cmds.listAttr.

args optional specific string pattern of an attribute to query on the node. This supports multiple string args

kargs keywords args supported by maya.cmds.listAttr

RETURNS OrderedDict or None

>>> ## get the names and values of all keyable attributes on this node
>>> keyable_map = node.getAttrMap(keyable=True)
>>>
>>> ## get names and values of all attributes that start with "trans"
>>> trans_attrs = node.getAttrMap("trans*")
getBasename()

Returns the string name of this node any namespaces.

RETURNS string base name

>>> node.getName()
>>> ## RESULT: "char:weapon:model:foo:testNode"
>>>
>>> node.getBasename()
>>> ## RESULT: "testNode"
getHashCode()

Returns a hash code for the internal Maya object referenced by the MObject within this MNode

RETURNS int hash code

>>> hash_code = node.getHashCode()
getInheritedNodeTypes()

Returns the node classes that this node type is inherited from.

RETURNS tuple of string node types or None

>>> node = MNode.createNode("transform", name="testNode")
>>>
>>> node.getInheritedNodeTypes()
>>> ## RESULT: ("containerBase", "entity", "dagNode", "transform")
getMObject()

Returns the MObject of this node

RETURNS OpenMaya.MObject

>>> m_obj = node.getMObject()
getMObjectHandle()

Returns the MObjectHandle of this node

RETURNS OpenMaya.MObjectHandle

>>> m_obj_hndl = node.getMObjectHandle()
getMenuCmds()

Return all custom marking menu items on this node.

RETURNS OrderedDict with string menu item names as keys and string python commands as values

getMessageAttr(attr_name)

Returns the node that is connected to the given message attribute.

attr_name string name of the message attr

RETURNS MNode or None

>>> connected_node = node.getMessageAttr("msgAttr")
getName()

Returns the string name of this node. Note that is is the short name of the object. This method does not return DAG node full paths. Returned name will include all parent namespaces.

RETURNS string name

>>> node_a = MNode.createNode("transform", name="testNode")
>>> node.getName()
>>> ## RESULT: "testNode"
getNamespace()

Return the namespace this node belongs to, if any. Any returned namespace will always start with “:”.

RETURN string namespace or None if node is in the default namespace

>>> node = MNode.createNode("transform", name="test_node")
>>> mc.namespace(add="test")
>>> node.rename("test:test_node")
>>>
>>> namespace = node.getNamespace()
>>> ##RESULT - ':test'
getNextAttr(attr_prefix, start_num=0, max_search=500)

Finds the next available attribute that is available with the given prefix. An int is added to the end of the given attr prefix. The attribute is not added.

attr_prefix string prefix to use for the attr

start_num int number to start from. default = 0

max_search int protection against infinite loop. An error RuntimeError is raised if an
attribute slot is not found after this many tries. default = 500

RETURNS string attribute name

>>> new_attr = node.getNextAttr("foo")
>>> ## RESULT: "foo0"
>>>
>>> node.addAttr(new_attr, "float")
>>> next_atr = node.getNextAttr("foo")
>>> ## RESULT: "foo1"
getObjectType()

Returns the string node type of this node.

RETURNS string node type

>>> node = MNode.createNode("transform", name="testNode")
>>>
>>> node.getObjectType()
>>> ## RESULT: "transform"
getPath()

Returns the full path name of this node. This is equivalent to casting the node as a string. If this node is not DAG, the name of the node will be returned.

RETURNS string

>>> node_a = MNode.createNode("transform", name="testNode")
>>> node.getName()
>>> ## RESULT: "testNode"
>>>
>>> node.getPath()
>>> ## RESULT: "|testNode"
>>>
>>> str(node)
>>> ## RESULT: "|testNode"
getPluginName()

Return the name of the plugin that defines this node, if any

RETURNS string name of the plugin where this node is defined or None if the node is native

getPlugs()

Returns the string names of all attributes that have incoming connections.

RETURNS tuple of attribute string names or None

>>>     plugs = node.getPlugs()
>>> ## RESULT: None
>>>
>>> node_b.connectAttr("tx", node, "tz")
>>>
>>>     plugs = node.getPlugs()
>>> ## RESULT: ("translateZ",)
getSetAttrCmds(attr_name, long_names=False, non_defaults_only=True)

Returns an tuple of strings containing mel setAttr commands for given attribute and all of its descendent attrs. This string could be used in a mayaAscii like format. This can be used to, if non_defaults_only is *True, test if the attribute has changed since the node was created.

attr_name string name of the attribute to query

long_names bool - whether to return cmds with long attribute names. default=False

non_defaults_only bool - If True, return a value only if the attribute has been change
from its default value or if its referenced and has been changed from

its referenced value. default=True

RETURNS tuple of string mel setAttr commands like you would see in a mayaAscii file or
None
>>> node = MNode.createNode("transform")
>>> node.setAttr("tx", 100.0)
>>> node.getSetAttrCmds("tx")
>>> #RESULT - [u'       setAttr ".tx" 100.0;']
>>>
>>> #translateY has not changed so it will return None with non_defaults_only set to True
>>> node.getSetAttrCmds("ty")
>>> #RESULT - None
hasAttr(attr_name, parent_attr=None)

Returns whether this node has an attribute with the given name.

attr_name string attr name

RETURNS bool

>>> node.hasAttr("foo")
>>> ## RESULT: False
>>>
>>> node.addAttr("foo", "float")
>>> node.hasAttr("foo")
>>> ## RESULT: True
hasUniqueName()

Indicates whether or not this node’s name is unique within the scene.

RETURNS bool

>>> node.hasUniqueName()
index(sub, start=None, end=None, include_namespaces=False)

String operartion just like str.index(). Return the lowest index in objects shortname where the substring sub is found such that sub is wholly contained in s[start:end]. Raises ValueError when the substring is not found.

sub string substring to find with the object’s shortname

start optional int start index

end optional int end index

include_namespaces bool - If False, namespaces in the object’s name will be ignored. default=False

RETURNS int index

isFromReferencedFile()

Indicates whether or not this node came from a referenced file.

RETURNS bool

isLocked()

Indicates whether or not this node is locked.

RETURNS bool

>>> node.isLocked()
isValid()

Tests whether this node is still valid. Nodes become invalid if deleted from the scene or a new scene is opened.

RETURNS bool

>>> node.isValid()
>>> ## RESULT: True
>>>
>>> node.delete()
>>> node.isValid()
>>> ## RESULT: False
isalnum(include_namespaces=False)

String operartion just like str.isalnum().

Return true if all characters in the nodes’s shortname are alphanumeric and there is at least one character, false otherwise. If include_namespaces arg is True, any ‘:’ characters in the node’s name will be ignored and not count towards the result of this method.

RETURNS bool

isalpha(include_namespaces=False)

String operartion just like str.isalpha().

Return true if all characters in the nodes’s shortname are alpha and there is at least one character, false otherwise. If include_namespaces arg is True, any ‘:’ characters in the node’s name will be ignored and not count towards the result of this method.

include_namespaces bool - If False, namespaces in the object’s name will be ignored. default=False

RETURNS bool

islower(include_namespaces=False)

String operartion just like str.islower().

Return true if all cased characters in the nodes’s shortname are lowercase and there is at least one cased character, false otherwise. If include_namespaces arg is True, any ‘:’ characters in the node’s name will be ignored and not count towards the result of this method.

include_namespaces bool - If False, namespaces in the object’s name will be ignored. default=False

RETURNS bool

istitle(include_namespaces=False)

String operartion just like str.istitle().

Return true if the nodes’s shortname is a titlecased string and there is at least one character, for example uppercase characters may only follow uncased characters and lowercase characters only cased ones. Return false otherwise. If include_namespaces arg is True, any ‘:’ characters in the node’s name will be ignored and not count towards the result of this method.

include_namespaces bool - If False, namespaces in the object’s name will be ignored. default=False

RETURNS bool

isupper(include_namespaces=False)

String operartion just like str.isupper().

Return true if all cased characters in the nodes’s shortname are upercase and there is at least one cased character, false otherwise. If include_namespaces arg is True, any ‘:’ characters in the node’s name will be ignored and not count towards the result of this method.

include_namespaces bool - If False, namespaces in the object’s name will be ignored. default=False

RETURNS bool

join(iterable, include_namespaces=False)

String operartion just like str.join().

Return a string which is the concatenation of the strings in the iterable. The separator while be the node’s shortname.

iterable sequence of strings to join using the node’s shortname as the separator

include_namespaces bool - If False, namespaces in the nodes’s name will be ignored. default=False

RETURNS string

listAttr(*args, **kargs)

List the atributes on this node

args specific string pattern of an attribute to query on the node. This supports
multiple string args

kargs keywords args supported by maya.cmds.listAttr RETURNS List of string atribute names or None

>>> ## list all attributes ##
>>> attrs = node.listAttr()
>>>
>>> ## list all translate attrs
>>> attrs = node.listAttr("translate*")
>>>
>>> ## list translate and rotate attrs
>>> attrs = node.listAttr("translate*", "rotate*")
listConnections(attr_name=None, **kargs)

List connections to this node

attr_name optional string name of an connected atribute. kargs keywords args supported by maya.cmds.listConnections RETURNS (MNodeList, None) if the “plugs” karg is not used.

(MNodeList, tuple*(*string attr_names)) if “plugs” is used.

(None, None) if there are no results.

>>>     nodes, plugs = node.listConnections(source=True)
lower(include_namespaces=False)

String operartion just like str.lower().

Return a copy of nodes’s shortname, but with upper case letters converted to lower case.

include_namespaces bool - If False, namespaces in the nodes’s name will be ignored. default=False

RETURNS string

classmethod ls(*args, **kargs)

Wrapper class method for maya.cmds.ls thats returns a MNodeList result instead of a list of string names

args args supported by maya.cmds.ls

kargs keyword args supported by maya.cmds.ls

RETURNS MNodeList of nodes or None

>>> foo_nodes = MNode.ls("foo*")
>>> time_nodes = MNode.ls(type="time")
lstrip(chars=None, include_namespaces=False)

String operartion just like str.lstrip().

Return a copy of the node’s shortname with leading characters removed. If chars is omitted or None, whitespace characters are removed. If given and not None, chars must be a string; the characters in the string will be stripped from the beginning of the string this method is called on.

chars optional string to strip from the node’s shortname

RETURNS string

partition(sep, include_namespaces=False)

String operartion just like str.partition().

Split the nodes’s shortname at the first occurrence of sep, and return a 3-tuple containing the part before the separator, the separator itself, and the part after the separator. If the separator is not found, return a 3-tuple containing the nodes’s shortname itself, followed by two empty strings.

include_namespaces bool - If False, namespaces in the nodes’s name will be ignored. default=False

RETURNS 3-tuple containing the part before the separator, the separator itself, and the part after the separator

removeInputConnections(attr_name)

Remove any incoming connections to the attribute with the given name.

attr_name string name of the attribute

RETURNS None

removeOutputConnections(attr_name)

Remove any output connections from the attribute with the given name.

attr_name string name of the attribute

RETURNS None

rename(new_name, **kargs)

Rename this node

new_name string new name kargs keywords args supported by maya.cmds.rename

RETURNS None

replace(old, new, count=None, include_namespaces=False)

String operartion just like str.replace().

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

old sub string in the objects name to replace

new string to replace sub-string old with

RETURNS string

rfind(sub, start=None, end=None, include_namespaces=False)

String operartion just like str.rfind(). Return the highest index in objects shortname where the substring sub is found such that sub is wholly contained in s[start:end]. Return -1 on failure

sub string substring to find with the object’s shortname

start optional int start index

end optional int end index

include_namespaces bool - If False, namespaces in the object’s name will be ignored. default=False

RETURNS int index or int -1 is sub-string not found

rindex(sub, start=None, end=None, include_namespaces=False)

String operartion just like str.rindex().

Return the highest index in objects shortname where the substring sub is found such that sub is wholly contained in s[start:end]. Raises ValueError when the substring is not found.

sub string substring to find with the object’s shortname

start optional int start index

end optional int end index

include_namespaces bool - If False, namespaces in the object’s name will be ignored. default=False

RETURNS int index

rpartition(sep, include_namespaces=False)

String operartion just like str.rpartition().

Split the nodes’s shortname at the last occurrence of sep, and return a 3-tuple containing the part before the separator, the separator itself, and the part after the separator. If the separator is not found, return a 3-tuple containing two empty strings, followed by the string itself.

include_namespaces bool - If False, namespaces in the nodes’s name will be ignored. default=False

RETURNS 3-tuple containing the part before the separator, the separator itself, and the part after the separator

rsplit(sep, maxsplit=None, include_namespaces=False)

String operartion just like str.rsplit().

Return a list of the words of the nodes’s shortname, scanning from the end. To all intents and purposes, the resulting list of words is the same as returned by split(), except when the optional third argument maxsplit is explicitly specified and nonzero. If maxsplit is given, at most maxsplit number of splits (the rightmost ones) occur, and the remainder of the string is returned as the first element of the list (thus, the list will have at most maxsplit+1 elements).

sep string delimiter to split by

maxsplit optional int limit the amount of splits

include_namespaces optional bool to include namespace in the test (default=False)

RETURNS list of strings

>>> node = MNode("super_awesome_naming_convention")
>>> node.split("_")
>>>     #RESULT - ['super', 'awesome', 'naming', 'convention']
rstrip(chars=None, include_namespaces=False)

String operartion just like str.lstrip().

Return a copy of the node’s shortname with trailing characters removed. If chars is omitted or None, whitespace characters are removed. If given and not None, chars must be a string; the characters in the string will be stripped from the beginning of the string this method is called on.

chars optional string to strip from the node’s shortname

RETURNS string

select(**kargs)

Selects this node with the given options.

kargs keywords args supported by maya.cmds.select RETURNS None

>>> node.select(repalce=True)
>>> node.select(deselect=True)
setAttr(attr_name, *args, **kargs)

Sets the given attr to the given value

attr_name string name of attr to set args args supported by maya.cmds.setAttr

kargs keywords arg supported by maya.cmds.setAttr

RETURNS None

>>> node.setAttr("translateX", 40.0)
setAttrsFromMap(attr_map, skip_missing=True)

Set attribute values from a dictionary object that has attribute names as keys and attribute values as values

attr_map dict or OrderedDict that has has attribute names as keys and attribute values as values skip_missing bool - whether to skip over attributes that exist in the incomming data

but not on the node. default=True

RETURNS None

>>> data = {"tx":1.0, "ty":2.0, "tz":3.0}
>>> node.setAttrsFromMap(data)
setDrivenKeyframe(attr, driver, driver_attr, **kargs)

Sets a set driven key on the current node using the given options

attr string name of the attr to be driven. Use this instead of the standard ‘attribute’ option driver MNode of the node to use as the driver. Use this with the driver_attr

arg instead of using the standard ‘currentDriver’ option

driver_attr string name of the attribute on the dirver node to use kargs keywords arg supported by maya.cmds.setDrivenKeyframe RETURNS None

setMessageAttr(attr_name, node, lock=True)

Connects the given node to the given message attribute on this node. If the attr does not exist, it is created.

attr_name string name of the message attr

node MNode of the node to connect

RETURNS MNode or None

>>> node_a = MNode.createNode("transform")
>>> node_b = MNode.createNode("transform")
>>>
>>> node_a.setMessageAttr("nodeB", node_b)
setStringAttr(attr_name, val, **kargs)

Sets the given value on the given string attr. If the attr does not exist, it is created. attr_name string name of the string attr val value to set the attr to. Non-string values will be cast to string.

RETURNS None

>>> node.setStringAttr("fooAttr", "fooVal")
split(sep, maxsplit=None, include_namespaces=False)

String operartion just like str.split().

Return a list of the words in the node name, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done (thus, the list will have at most maxsplit+1 elements). If maxsplit is not specified or -1, then there is no limit on the number of splits (all possible splits are made).

If sep is given, consecutive delimiters are not grouped together and are deemed to delimit empty strings (for example, ‘1,,2’.split(‘,’) returns [‘1’, ‘’, ‘2’]). The sep argument may consist of multiple characters (for example, ‘1<>2<>3’.split(‘<>’) returns [‘1’, ‘2’, ‘3’]). Splitting an empty string with a specified separator returns [‘’].

If sep is not specified or is None, a different splitting algorithm is applied: runs of consecutive whitespace are regarded as a single separator, and the result will contain no empty strings at the start or end if the string has leading or trailing whitespace. Consequently, splitting an empty string or a string consisting of just whitespace with a None separator returns [].

sep string delimiter to split by

maxsplit optional int limit the amount of splits

include_namespaces optional bool to include namespace in the test (default=False)

RETURNS list of strings

>>> node = MNode("super_awesome_naming_convention")
>>> node.split("_")
>>>     #RESULT - ['super', 'awesome', 'naming', 'convention']
startswith(prefix, start=None, end=None, include_namespaces=False)

String operartion just like str.startswith().

Return True if nodes’ shortname starts with the prefix, otherwise return False. prefix can also be a tuple of prefixes to look for. With optional start, test string beginning at that position. With optional end, stop comparing string at that position.

prefix string or tuple of strings to test against

start optional int test beginning at position

end optional int stop comparing at position

include_namespaces optional bool to include namespace in the test (default=False)

RETURNS bool

>>> node = MNode("cool_node")
>>> node.startswith("cool_")
>>> #RESULT - True
strip(chars=None, include_namespaces=False)

String operartion just like str.strip().

Return a copy of the node’s shortname with leading and trailing characters removed. If chars is omitted or None, whitespace characters are removed. If given and not None, chars must be a string; the characters in the string will be stripped from the both ends of the string this method is called on.

chars optional string to strip from the node’s shortname

RETURNS string

swapcase(include_namespaces=False)

String operartion just like str.swapcase().

Return a copy of node’s shortname, but with lower case letters converted to upper case and vice versa.

RETURNS string

upper(include_namespaces=False)

String operartion just like str.upper(). Return a copy of object’s shortname, but with lower case letters converted to upper case.

RETURNS string

Previous topic

mpylib Package

Next topic

MNodeList