This is my 2nd noob question for today... so bear with me. So this is supposed to loop through 'nothing'
and 'persp'
while still renaming/printing After:[u’concrete_file1’]
because of the continue;
statement, but I just get empty brackets. I ran the same function without this:
if not (maya.cmds.ls(texture) and
maya.cmds.nodeType(texture)=='file'):
continue;
And without 'nothing'
and 'persp'
and it worked fine so I'm assuming the problem is in there somewhere, but after fiddling with it for a while I still don't know what it is... This'll probably be some super simplistic answer but I'm on day 2 of learning this stuff so ¯\_(ツ)_/¯
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: []
Also I'm just using the Maya Script Editor to write all this, is there a better editor that might be easier?
Include an else
to make the statements after continue;
run when if not (maya.cmds.ls(texture) and maya.cmds.nodeType(texture)=='file'):
is not true.
What happens here, is that there is only that one condition. Whenever that is true, it evaluates continue;
and skips the rest of the statements. However, whenever that is not true, it also skips new_texture_names.append(maya.cmds.rename(texture, '%s%s'%(pre, texture)));
because that is inside the if
condition.