如何在Maya中使用Python选择新生成的节点?

时间:2017-05-08 16:04:07

标签: python maya

我正在尝试通过将多边形面包裹到另一个多边形形状来创建自动化来复制形状

# 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.

我的问题:有没有办法选择新的transferAttributes节点并将其传递给cmds.setAttr()

PS:transferAttributes*.searchMethod可能有效,但会选择所有transferAttributes个节点。

2 个答案:

答案 0 :(得分:2)

'Pseudo code ElseIf firstTimeRun = True Then welcome += 1 txtDisplay.text = texts.ngs(welcome) 将返回其创建的节点的名称:

cmds.transferAttributes

答案 1 :(得分:0)

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 )