MPyNode

class MPyNode(node=None, name=None, exp_str=None, input_map=None, output_map=None, stored_var_map=None)

Bases: mpylib.MNode

Universal Python API node

Methods Summary

addInputAttr(long_name, attr_type[, is_array]) Adds an input attribute of the given long name and given type to the node.
addOutputAttr(long_name, attr_type[, is_array]) Adds an output attribute of the given long name and given type to the node.
addStoredVariable(var_name) Used to flag an instance property on the node for storage on disc when the file is saved.
deleteInputAttr(attr_name) Removes the given input attribute from the node.
deleteOutputAttr(attr_name) Removes the given output attribute from the node.
exportToFile(file_path[, use_binary]) Export this node to an external file
getExpression() Returns the current python expression within the node.
getInputAttrMap() Returns a dictionary with all input attr names as keys and attribute data as values.
getOutputAttrMap() Returns a dictionary with all output attr names as keys and attribute data as values.
getStoredVariables() Returns the nodes “stored variables” as a dictionary.
hasStoredVariable(var_name) Returns whether the node has an instance property with the given name that has been flagged for storage on disc.
importFromFile(file_path) Import a MPyNode from an external file.
listInputAttrs() Returns the names of the node’s input attributes
listOutputAttrs() Returns the names of the node’s output attributes
listStoredVariables() Returns the names of the node’s internally stored variables
listValidInputTypes() Class method returns the types of supported input attributes
listValidOutputTypes() Class method returns the types of supported output attributes
ls(\*args, \*\*kargs) class method - returns the nodes of type ‘mPyNode’ in the current scene.
removeStoredVariable(var_name) Removes the given variable name from the list of variables that will stored to file
setExpression(exp_str) Set the expression within the node to the given string of python code.
setStoredVariable(var_name, var_val) Used to set an instance property on the node for use in the expression and storage on disc when the file is saved.
setVariable(var_name, var_val) Used to set an instance property on the node for use in the expression.

Methods Documentation

addInputAttr(long_name, attr_type, is_array=False, **kargs)

Adds an input attribute of the given long name and given type to the node. Use MPyNode.listSupportedAttrTypes() to list supported types

Parameters:
long_name : str

long name of the attribute to add. This will be the name of its variable in the expression

attr_type : str

type of attribute to add. Use MPyNode.listSupportedAttrTypes() to list supported types

is_array : bool, optional, default = False

whether to make this an array attribute

kargs : keyword args, optional

keyword args supported by maya.cmds.addAttr

Returns:
*None*

See also

addOutputAttr
Adds an output attribute of the given long name and given type to the node.
addStoredVariable
Used to flag an instance property on the node for storage on disc when the file is saved

Examples

>>> node.addInputAttr("floatAttr", "float")
>>> node.addInputAttr("floatArrayAttr", "float", is_array=True)
addOutputAttr(long_name, attr_type, is_array=False, **kargs)

Adds an output attribute of the given long name and given type to the node. Use MPyNode.listSupportedAttrTypes() to list supported types

Parameters:
long_name : str

long name of the attribute to add. This will be the name of its variable in the expression

attr_type : str

type of attribute to add. Use MPyNode.listSupportedAttrTypes() to list supported types

is_array : bool, optional, default = False

whether to make this an array attribute

kargs : keyword args, optional

keyword args supported by maya.cmds.addAttr

Returns:
*None*

See also

addInputAttr
Adds an output attribute of the given long name and given type to the node.
addStoredVariable
Used to flag an instance property on the node for storage on disc when the file is saved

Examples

>>> node.addOutputAttr("floatAttr", "float")
>>> node.addOutputAttr("floatArrayAttr", "float", is_array=True)
addStoredVariable(var_name)

Used to flag an instance property on the node for storage on disc when the file is saved. The name given should refer to a property on the node instance created/used by the expression (i.e. self.var_name)

Parameters:
var_name : str

name of the variable to store

Returns:
*None*

See also

addInputAttr
Adds an input attribute of the given long name and given type to the node.
addOutputAttr
Adds an output attribute of the given long name and given type to the node.

Examples

>>> node.addStoredVariable("myVar")
deleteInputAttr(attr_name)

Removes the given input attribute from the node.

Parameters:
attr_name : str

string name of the input attribute to remove

Returns:
*None*

See also

deleteOutputAttr
Removes the given output attribute from the node.
removeStoredVariable
Removes the given variable name from the list of variables that will stored to file

Examples

>>> node.deleteInputAttr("myVar")
deleteOutputAttr(attr_name)

Removes the given output attribute from the node.

Parameters:
attr_name : str

string name of the output attribute to remove

Returns:
*None*

See also

deleteInputAttr
Removes the given input attribute from the node.
removeStoredVariable
Removes the given variable name from the list of variables that will stored to file

Examples

>>> node.deleteOutputAttr("myVar")
exportToFile(file_path, use_binary=True)

Export this node to an external file

Parameters:
file_path : str

string file path to export to. Directory structure must exist

use_binary : bool, optional, default=True

By default, a binary file is exported. If a text format is desired, set this to False

Returns:
*None*

See also

importFromFile
Import a MPyNode from an external file. An nstance of the node will be constructed in the current Maya scene

Examples

>>> node.exportToFile("C:/temp/file_name.ext")
>>> node.exportToFile("C:/temp/file_name.ext", use_binary=False)
getExpression()

Returns the current python expression within the node.

Returns:
*str* or *None*

See also

setExpression
Set the expression within the node to the given string of python code.

Examples

>>> exp = node.getExpression()
getInputAttrMap()

Returns a dictionary with all input attr names as keys and attribute data as values. The values of the dictionary are also dictiontaries with the proper addInputAttr() keyword args and values. Note that only non-default keyword args are returned. So if an attribute is not “keyable”, for example, no “keyable” keyword will be returned in dictionary.

Returns:
*dict* with all input attr names as keys and attribute data as values or *None*

See also

addInputAttr
Adds an input attribute of the given long name and given type to the node.

Examples

>>> input_map = node.getInputAttrMap()
getOutputAttrMap()

Returns a dictionary with all output attr names as keys and attribute data as values. The values of the dictionary are also dictiontaries with the proper addOutputAttr() keyword args and values. Note that only non-default keyword args are returned. So if an attribute is not “keyable”, for example, no “keyable” keyword will be returned in dictionary.

Returns:
*dict* with all output attr names as keys and attribute data as values or *None*

See also

addOutputAttr
Adds an output attribute of the given long name and given type to the node.

Examples

>>> input_map = node.getOutputAttrMap()
getStoredVariables()

Returns the nodes “stored variables” as a dictionary.

Returns:
*dict* or *None* - Keys are string names of the variables and values are their current values

See also

addStoredVariable
Removes the given output attribute from the node.
setStoredVariable
Used to set an instance property on the node for use in the expression and storage on disc when the file is saved

Examples

>>> var_map = node.getStoredVariables()
hasStoredVariable(var_name)

Returns whether the node has an instance property with the given name that has been flagged for storage on disc.

Parameters:
var_name : str

name of the variable

Returns:
*bool*

See also

addStoredVariable
Removes the given output attribute from the node.

Examples

>>> node.hasStoredVariable("myVar")
static importFromFile(file_path)

Import a MPyNode from an external file. An instance of the node will be constructed in the current Maya scene

Parameters:
file_path : str

file path to import from

Returns:
*MPyNode* of the newly created node

See also

importFromFile
Export this node to an external file

Examples

>>> new_node = MPyNode.importFromFile("C:/temp/file_name.ext")
listInputAttrs()

Returns the names of the node’s input attributes

Returns:
*tuple* of *str* attribute names or *None*

See also

addInputAttr
Adds an input attribute of the given long name and given type to the node.

Examples

>>> input_attrs = node.listInputAttrs()
listOutputAttrs()

Returns the names of the node’s output attributes

Returns:
*tuple* of *str* attribute names or *None*

See also

addOutputAttr
Adds an output attribute of the given long name and given type to the node.

Examples

>>> output_attrs = node.listOutputAttrs()
listStoredVariables()

Returns the names of the node’s internally stored variables

Returns:
*tuple* of *str* variable names or *None*

See also

addStoredVariable
Used to flag an instance property on the node for storage on disc when the file is saved.

Examples

>>> stored_vars = node.listStoredVariables()
classmethod listValidInputTypes()
Class method returns the types of supported input attributes
Returns:
*tuple* of *str* attribute types or *None*

See also

addInputAttr
Adds an input attribute of the given long name and given type to the node.

Examples

>>> attr_types = MPyNode.listValidInputTypes()
classmethod listValidOutputTypes()

Class method returns the types of supported output attributes

Returns:
*tuple* of *str* attribute types or *None*

See also

addOutputAttr
Adds an output attribute of the given long name and given type to the node.

Examples

>>> attr_types = MPyNode.listValidInputTypes()
classmethod ls(*args, **kargs)

class method - returns the nodes of type ‘mPyNode’ in the current scene. Works just like maya.cmds.ls

Parameters:
args : str

args supported by maya.cmds.ls

kargs : str

keyword args supported by maya.cmds.ls

Returns:
*tuple* of *MPyNode* nodes or *None*

Examples

>>> ## get all mPyNode nodes in the scene
>>> nodes = MPyNode.ls()
>>>
>>> ## get all mPyNode nodes whose names start with "Foo"
>>> foo_nodes = MPyNode.ls("Foo*")
removeStoredVariable(var_name)

Removes the given variable name from the list of variables that will stored to file

Parameters:
var_name : str

name of the variable to remove

Returns:
*None*

See also

addStoredVariable
Used to flag an instance property on the node for storage on disc when the file is saved

Examples

>>> node.removeStoredVariable("floatAttr")
setExpression(exp_str)

Set the expression within the node to the given string of python code.

Parameters:
exp_str : str

python code to set the expression to.

Returns:
*None*

See also

getExpression
Returns the current python expression within the node.

Examples

>>> py_node.setExpression('outAttr = inAttr * 2')
setStoredVariable(var_name, var_val)

Used to set an instance property on the node for use in the expression and storage on disc when the file is saved. The name given should refer to a property on the node instance created/used by the expression (i.e. self.var_name)

Parameters:
var_name : str

name of the variable to set

var_val : object

python value to assign to the variable

Returns:
*None*

See also

getStoredVariable
Returns the nodes “stored variables” as a dictionary.

Examples

>>> node.setStoredVariable("myVar", var_val)
setVariable(var_name, var_val)

Used to set an instance property on the node for use in the expression. The name given should refer to a property on the node instance created/used by the expression (i.e. self.var_name). This value variable is destroyed when the Maya scene is closed.

Parameters:
var_name : str

name of the variable to set

var_val : object

python value to assign to the variable

Returns:
*None*

Examples

>>> node.setVariable("myVar", 1.0)