2017-05-08 2 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

を修正しました。タンスク – 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) 
関連する問題