Reputation: 481
I am trying to create an automation to copy a shape by wrapping a polygon face to another polygon shape
# This script wrap a polygon face to the targeted terrain
import maya.cmds as cmds
# select terrain first, then the face
cmds.select( 'terrain', r = True )
cmds.select( 'face', add = True )
# wrapping a polygon face to the terrain
cmds.transferAttributes( transferPositions = 1 )
# NEW Node transferAttributes1 is created, change its attribute searchMethod to 1.
cmds.setAttr( 'transferAttributes1.searchMethod' , 1 )
# transferAttributes1 is generated after execution of
# cmds.transferAttributes( transferPositions = 1 ).
# The name might be different, such as transferAttributes2, transferAttributes3, etc.
# and cmds.setAttr( 'transferAttributes1.searchMethod' , 1 ) might give errors.
My question: Is there any way to select the new transferAttributes
node and pass it to cmds.setAttr()
?
PS: transferAttributes*.searchMethod
might work, but it will select all transferAttributes
nodes.
Upvotes: 0
Views: 474
Reputation: 12218
cmds.transferAttributes
will return the name of the node it creates:
cmds.select( 'terrain', r=True )
cmds.select( 'face', add=True )
new_node = cmds.transferAttributes( transferPositions=1 )[0]
cmds.setAttr( new_node +'.searchMethod' , 1 )
Upvotes: 2
Reputation: 481
import maya.cmds as cmds
cmds.select( 'terrain1', r=True )
cmds.select( 'face1', add=True )
cmds.transferAttributes( transferPositions=1 )
#select every transferAttributes Node and store them in a list.
selection = cmds.ls('transferAttributes*');
#sort the list.
selection.sort()
#select the last element from the list, thus the most recent node
key = selection[-1]
cmds.setAttr( key+'.searchMethod' , 1 )
Upvotes: 0