2017-09-08 2 views
2

私はMaya Pythonの速度を上げようとしているので、この本(http://www.maya-python.com/)をオンラインで読むことができます。 )ここで私は正しい結果を得ていないが、私はまた何の誤りも得ていない。もし誰かがこれを見て、何が問題を引き起こしているのかというアイディアを素晴らしいものにすることができたら。Maya Pythonのノード名の変更について

したがって、3つのファイルノードを細かく作成し、すべての3つのノードの名前を「dirt_」という接頭辞に変更することになっています。しかし、それは唯一の「FILE1」とされていない他の二つのノードここ

の名前を変更するプロセスです:

#The FOR statement 

import maya.cmds; 
def process_all_textures(**kwargs): 
    pre = kwargs.setdefault('prefix', 'my_'); 
    textures = kwargs.setdefault('texture_nodes'); 
    new_texture_names = []; 
    for texture in textures: 
     new_texture_names.append(
     maya.cmds.rename(
     texture, 
     '%s%s'%(pre, texture) 
     ) 
     ); 
     return new_texture_names; 

#create new Maya scene & list 3 file nodes & print their names 

maya.cmds.file(new=True, f=True); 
textures = []; 
for i in range(3): 
    textures.append(
    maya.cmds.shadingNode(
    'file', 
    asTexture=True 
    ) 
    ); 
print(textures); 

#pass new texture list to process_all_textures() func and print resulting names 

new_textures = process_all_textures(
texture_nodes = textures, 
prefix = 'dirt_' 
); 
print(new_textures); 

[u'file1', u'file2', u'file3'] 
[u'dirt_file1'] 

答えて

1

return new_texture_namesは、4つのスペースでインデントされなければならない行(いない8つのものによります)。

returnステートメントは、関数を停止してすぐに値を返します。

#The FOR statement 
import maya.cmds as mc 

def process_all_textures(**kwargs): 
    pre = kwargs.setdefault('prefix', 'my_') 
    textures = kwargs.setdefault('texture_nodes') 
    new_texture_names = [] 

    for texture in textures: 
     new_texture_names.append(mc.rename(texture,'%s%s'%(pre, texture))) 

    return new_texture_names 

#create new Maya scene & list 3 file nodes & print their names 
mc.file(new=True,f=True) 
textures = [] 

for i in range(3): 
    textures.append(mc.shadingNode('file',asTexture=True)) 
print(textures) 

#pass new texture list to process_all_textures() func and print resulting names 
new_textures = process_all_textures(texture_nodes = textures,prefix = 'dirt_') 
print(new_textures) 

[u'file1', u'file2', u'file3'] 
[u'dirt_file1'] 
+1

ありがとうございました!私が従っている本は字下げを表示しないので、私はそれを見守らなければならないだろうと思う。 – Mogie

+1

Return文は、一度満たされると機能を停止する。それで、毎回最初のループで停止します – DrWeeny

関連する問題