代码之家  ›  专栏  ›  技术社区  ›  Mogie

继续并中断语句执行相同的操作

  •  1
  • Mogie  · 技术社区  · 9 年前

    'nothing' 和 'persp' 仍在重命名/打印时 After:[u’concrete_file1’] 因为 continue; 声明,但我只得到了空括号。我在没有这个的情况下运行了相同的函数:

            if not (maya.cmds.ls(texture) and
            maya.cmds.nodeType(texture)=='file'):
                continue;
    

    而且没有 和 它工作得很好,所以我假设问题在那里的某个地方,但在摆弄了一段时间后,我仍然不知道它是什么。。。这可能是一个非常简单的答案,但我正在第二天学习这些东西,所以 ¯\_(ツ)_/¯

    def process_all_textures(**kwargs):
        pre = kwargs.setdefault('prefix');
        if (isinstance(pre, str) or
        isinstance(pre, unicode)):
            if not pre[-1] == '_':
                pre += '_';
        else: pre = '';
        textures = kwargs.setdefault('texture_nodes');
        new_texture_names = [];
        if (isinstance(textures, list) or
        isinstance(textures, tuple)):
            for texture in textures:
                if not (maya.cmds.ls(texture) and
                maya.cmds.nodeType(texture)=='file'):
                    continue;
                    new_texture_names.append(
                    maya.cmds.rename(
                    texture,
                    '%s%s'%(pre, texture)
                    )
                    );
            return new_texture_names;
        else:
            maya.cmds.error('No texture nodes specified');
    
    #Should skip over the 2 invalid objects ('nothing' & 'persp')
    #because of the continue statement...
    
    new_textures= [
    'nothing',
    'persp',
    maya.cmds.shadingNode('file', asTexture=True)
    ];
    print ('Before: %s'%new_textures);
    new_textures = process_all_textures(
    texture_nodes = new_textures,
    prefix = 'concrete_'
    );
    print ('After: %s'%new_textures);
    
    Before: ['nothing', 'persp', u'file1']
    After: []
    

    1 回复  |  直到 9 年前
        1
  •  1
  •   Antimony Jeff Evernham    9 年前

    包括 else continue; 运行时间 if not (maya.cmds.ls(texture) and maya.cmds.nodeType(texture)=='file'): 这不是真的。

    持续 并跳过其余语句。然而,如果这不是真的,那么 而且 跳过 new_texture_names.append(maya.cmds.rename(texture, '%s%s'%(pre, texture))); 因为那是在 if 条件