2017-05-08 50 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)