2017-05-08 2 views
0

Ich versuche, eine Automatisierung zu schaffen eine Form durch Wickeln eines Polygonfläche auf eine andere PolygonformWie neu generierten Knoten mit Python in Maya auswählen?

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

Meine Frage zu kopieren: Gibt es eine Möglichkeit, die neuen transferAttributes Knoten und übergeben es an cmds.setAttr() zu wählen?

PS: transferAttributes*.searchMethod könnte funktionieren, aber es werden alle transferAttributes Knoten ausgewählt.

Antwort

2

cmds.transferAttributes den Namen des Knotens zurückkehren es schafft:

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

Dank einer Million! –

+0

cmds.transferAttributes (transferPositions = 1) gibt eine String-Liste zurück. new_node gibt [utransferAttributes1 '] aus, also cmds.setAttr (new_node [0] +'. searchMethod ', 1) –

+0

Behoben, ich habe es aus dem Speicher ohne Überprüfung gemacht. 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)