2017-05-08 44 views
0

我试图创建一个自动化通过包装多边形面到另一个多边形如何在Maya中使用Python选择新生成的节点?

# 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

cmds.transferAttributes将返回它创建的节点的名称:

cmds.select('terrain', r=True) 
cmds.select('face', add=True) 
new_node = cmds.transferAttributes(transferPositions=1)[0] 
cmds.setAttr(new_node +'.searchMethod' , 1) 
+0

万分感谢! –

+0

cmds.transferAttributes(transferPositions = 1)返回一个字符串列表。 new_node打印[u'transferAttributes1'],所以cmds.setAttr(new_node [0] +'。searchMethod',1) –

+0

固定,我没有检查内存。 Thansk – theodox

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)