pymel.core.rendering.nodePreset

static rendering.nodePreset(*args, **kwargs)

Command to save and load preset settings for a node. This command allows you to take a snapshot of the values of all attributes of a node and save it to disk as a preset with user specified name. Later the saved preset can be loaded and applied onto a different node of the same type. The end result is that the node to which the preset is applied takes on the same values as the node from which the preset was generated had at the time of the snapshot.

Flags:
Long name (short name) Argument Types Properties
attributes (atr) unicode ../../../_images/create.gif
 

A white space separated string of the named attributes to save to the preset file. If not specified, all attributes will be stored. Flag can have multiple arguments, passed either as a tuple or a list.

custom (ctm) unicode ../../../_images/create.gif
 

Specifies a MEL script for custom handling of node attributes that are not handled by the general save preset mechanism (ie. multis, dynamic attributes, or connections). The identifiers #presetName and #nodeName will be expanded before the script is run. The script must return an array of strings which will be saved to the preset file and issued as commands when the preset is applied to another node. The custom script can query #nodeName in determining what should be saved to the preset, or issue commands to query the selected node in deciding how the preset should be applied.

delete (delete) PyNode, <type ‘unicode’> ../../../_images/create.gif
 
Deletes the existing preset for the node specified by the first argument with the name specified by the second argument.
exists (ex) PyNode, <type ‘unicode’> ../../../_images/create.gif
 

Returns true if the node specified by the first argument already has a preset with a name specified by the second argument. This flag can be used to check if the user is about to overwrite an existing preset and thereby provide the user with an opportunity to choose a different name.

isValidName (ivn) unicode ../../../_images/create.gif
 

Returns true if the name consists entirely of valid characters for a preset name. Returns false if not. Because the preset name will become part of a file name and part of a MEL procedure name, some characters must be disallowed. Only alphanumeric characters and underscore are valid characters for the preset name.

list (ls) PyNode ../../../_images/create.gif
 
Lists the names of all presets which can be loaded onto the specified node.
load (ld) PyNode, <type ‘unicode’> ../../../_images/create.gif
 

Sets the settings of the node specified by the first argument according to the preset specified by the second argument. Any attributes on the node which are the destinations of connections or whose children (multi children or compound children) are destinations of connections will not be changed by the preset.

save (sv) PyNode, <type ‘unicode’> ../../../_images/create.gif
 

Saves the current settings of the node specified by the first argument to a preset of the name specified by the second argument. If a preset for that node with that name already exists, it will be overwritten with no warning. You can use the -exists flag to check if the preset already exists. If an attribute of the node is the destination of a connection, the value of the attribute will not be written as part of the preset.

Derived from mel command maya.cmds.nodePreset

Example:

import pymel.core as pm

# To determine if "My Special Settings" is a valid name for a preset (it
# is not because it contains spaces):
#
pm.nodePreset(isValidName="My Special Settings" )
# Result: False #
# To save the settings of nurbsSphereShape1 as a preset called "smithers":
#
pm.nodePreset( save=("nurbsSphereShape1","smithers") )
# To get a list of all presets available that could be applied to
# nurbsSphereShape1:
#
pm.nodePreset( list='nurbsSphereShape1' )
[u'smithers', u'smoothSphere', u'roughSphere', u'atmoSphere']
# To load the preset named "smoothSphere" onto nurbsSphereShape1:
#
pm.nodePreset( load=('nurbsSphereShape1', 'smoothSphere') )
# To delete the preset named "smithers" which was formerly available for the
# node nurbsSphereShape1 (and other nodes of the same type):
#
pm.nodePreset( delete=('nurbsSphereShape1', 'smithers') )
# To determine if a preset named "smithers" exists for the node
# nurbsSphereShape1 (it does not because it has been deleted):
#
pm.nodePreset( exists=('nurbsSphereShape1', 'smithers') )
0
# Create a preset containing only the color and diffuse attributes:
#
pm.nodePreset( save=("lambert1","colorAndDiffuse"), attributes='color diffuse' )
# Create a preset to map a checker texture to the applied node.
# Because the "custom" callback is required to return an array of MEL commands,
# each line of python in the array must be wrapped by the MEL "python" command.
#
def customChecker():
    doCheckerCmds = [
            # Get the name of the node to apply the checker to.
            "python( \"selection = pm.ls( selection=True )\" );",
        "python( \"nodeName = selection[0]\" );",
        # Create a checker texture.
        "python( \"checkerName = pm.shadingNode( 'checker', asTexture=True )\" );",
        # Connect the checker to the node the preset is applied to.
            "python( \"pm.connectAttr( (checkerName+\\\".outColor\\\"), (nodeName+\\\".color\\\") )\" );"
            ]
    return doCheckerCmds
    pm.nodePreset(custom="python( \"customChecker()\" )", save=('lambert1', 'checkered') )

Previous topic

pymel.core.rendering.nodeIconButton

Next topic

pymel.core.rendering.ogsRender

Core

Core Modules

Other Modules

This Page