MNodeList

class MNodeList(nodes=None)

Bases: object

List type object, used for storing MNode type objects

Methods Summary

addAttr(long_name, attr_type, **kargs) Adds an attribute of the given long name and given type to all the nodes in the list.
append(item) Built-in method.
bakeResults(*args, **kargs) Run bakeResults on nodes in this list with the given options
count(node)
purpose:Returns the number of occurances of the given node in the list
delete() Delete all nodes in the list.
extend(item) Built-in method.
getAttr(attr_name[, skip_missing]) Returns the value of the given attr on every node in the list.
getAttrMap(*args, **kargs) Returns an OrderedDict of all MNodes is this list as keys and OrderedDict of attributes/values as values.
index(x)
listNodesOfType(node_type) Return the nodes within this list that match the given node type.
listNodesWithAttr(attr_name) Return the nodes within this list that have an attribute with the given name.
setAttr(attr_name[, val, skip_missing]) Sets the given attr to the given value on all nodes in the list

Methods Documentation

addAttr(long_name, attr_type, **kargs)

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

Parameters:
  • long_name – string long name of the attribute to add
  • 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
Returns:

None

>>> node_list.addAttr("test", "float", keyable=True)
append(item)

Built-in method.

bakeResults(*args, **kargs)

Run bakeResults on nodes in this list 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_list.bakeResults()
count(node)
Purpose:Returns the number of occurances of the given node in the list
Returns:int
delete()

Delete all nodes in the list. List will be empty after caliing this method.

RETURNS None

extend(item)

Built-in method.

getAttr(attr_name, skip_missing=False, **kargs)

Returns the value of the given attr on every node in the list. Can optionally skip or error on missing attributes. If a missing attr is skipped, the resulting tuple will have placeholder None values representing those nodes.

Parameters:
  • attr_name – string name of attr
  • skip_missing
    bool - True to quietly skip any nodes that are missing the
    given attr. Missing attrs will result of None in the returned tuple.

    False will throw an exception on missing attr. default=False

  • kargs – keywords arg supported by maya.cmds.getAttr
Returns:

tuple of attribute values or None. Returned tuple indices will correspond to the indices of the nodes in this list.

getAttrMap(*args, **kargs)

Returns an OrderedDict of all MNodes is this list as keys and OrderedDict of attributes/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_list.getAttrMap(keyable=True)
>>>
>>> ## get names and values of all attributes that start with "trans"
>>> trans_attrs = node_list.getAttrMap("trans*")
index(x)
listNodesOfType(node_type)

Return the nodes within this list that match the given node type.

node_type string node type

RETURNS MNodeList or None

listNodesWithAttr(attr_name)

Return the nodes within this list that have an attribute with the given name.

attr_name string attribute name

RETURNS MNodeList or None

setAttr(attr_name, val=None, skip_missing=False, **kargs)

Sets the given attr to the given value on all nodes in the list

Parameters:
  • attr_name – string name of attr to set
  • val – value to set the attribute to. This arg is optional if setting attribute properties instead of value.
  • skip_missing – bool - True to quietly skip any nodes that are missing the given attr. False will throw an exception on missing attr. default=False
  • kargs – keywords arg supported by maya.cmds.setAttr
Returns:

None

Previous topic

MNode

Next topic

MUndo