pymel.core.general.nodeCast

nodeCast(*args, **kwargs)

Given two nodes, a source node of type A and a target node of type B, where type A is either type B or a sub-type of B, this command will replace the target node with the source node. That is, all node connections, DAG hierarchy and attribute values on the target node will be removed from the target node and placed on the source node. This operation will fail if either object is referenced, locked or if the nodes do not share a common sub-type. This operation is atomic. If the given parameters fail, then the source and target nodes will remain in their initial state prior to execution of the command. IMPORTANT: the command will currently ignore instance connections and instance objects. It will also ignore reference nodes.

Flags:
Long name (short name) Argument Types Properties
copyDynamicAttrs (cda) bool ../../../_images/create.gif
 

If the target node contains any dynamic attributes that are not defined on the source node, then create identical dynamic attricutes on the source node and copy the values and connections from the target node into them.Flag can appear in Create mode of commandFlag can have multiple arguments, passed either as a tuple or a list.

disableAPICallbacks (dsa) bool ../../../_images/create.gif
 
add comment
| .. |
dsj)** | bool | .. image:: /images/create.gif |
 
add comment
| .. |
dua)** | bool | .. image:: /images/create.gif |
 

If the node that is being swapped out has any connections that do not exist on the target node, then indicate if the connection should be disconnected. By default these connections are not removed because they cannot be restored if the target node is swapped back with the source node.

force (f) bool ../../../_images/create.gif
 

Forces the command to do the node cast operation even if the nodes do not share a common base object. When this flag is specified the command will try to do the best possible attribute matching when swapping the command. It is notrecommended to use the ‘-swapValues/sv’ flag with this flag.

swapNames (sn) bool ../../../_images/create.gif
 
Swap the names of the nodes. By default names are not swapped.
swapValues (sv) bool ../../../_images/create.gif
 

Indicates if the commands should exchange attributes on the common attributes between the two nodes. For example, if the nodes are the same base type as a transform node, then rotate, scale, translate values would be copied over.

Derived from mel command maya.cmds.nodeCast

Example:

import pymel.core as pm

import maya.cmds as cmds

tr1 = pm.createNode( 'transform' )
tr2 = pm.createNode( 'transform' )
pm.connectAttr( tr1 + ".t", tr2 + ".t" )
pm.connectAttr( tr2 + ".r", tr1 + ".r" )
theT = tr1
pm.select( theT, replace=1 )
pm.addAttr( ln="unmatched", at="long" )
middle_man = pm.createNode( 'transform' )
pm.connectAttr( theT + ".unmatched", middle_man + ".tx" )
swapNode = pm.createNode( 'transform' )
pm.nodeCast( theT, swapNode, disconnectUnmatchedAttrs=true )

Previous topic

pymel.core.general.move

Next topic

pymel.core.general.nodeType

Core

Core Modules

Other Modules

This Page