Rename all objects in list with name of an other lists

29 views
Skip to first unread message

denis hoffmann

unread,
Feb 23, 2017, 11:14:52 AM2/23/17
to Python Programming for Autodesk Maya
Hey guys,

I want to rename all shaders with names from a list.

so I make a list of all shaders and a var with all names I want to have.

ShaderNames = [u'Shader0', u'Shader1', u'Shader2', u'Shader3', u'Shader4', u'Shader5']

NewNames = ['Name1', 'Name2', 'Name3', 'Name4', 'Name5']


what is the solution if I want to have my "Shader0"  new name is "Name1"

Thank You very mutch!!!


f.michal

unread,
Feb 23, 2017, 12:53:08 PM2/23/17
to python_in...@googlegroups.com
smth like this...

for i in xrange(len(ShaderNames)):
    rename ShaderNames[i]  NewNames[i]


W dniu 2017-02-23 o 17:14, denis hoffmann pisze:
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/a9ca5154-c746-4b35-8789-088d654186b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robert White

unread,
Feb 23, 2017, 12:57:59 PM2/23/17
to Python Programming for Autodesk Maya
for shader_name, new_name in zip(ShaderNames, newNames):
    rename shader_name, new_name


On Thursday, February 23, 2017 at 11:53:08 AM UTC-6, Michał Frątczak wrote:
smth like this...

for i in xrange(len(ShaderNames)):
    rename ShaderNames[i]  NewNames[i]


W dniu 2017-02-23 o 17:14, denis hoffmann pisze:
Hey guys,

I want to rename all shaders with names from a list.

so I make a list of all shaders and a var with all names I want to have.

ShaderNames = [u'Shader0', u'Shader1', u'Shader2', u'Shader3', u'Shader4', u'Shader5']

NewNames = ['Name1', 'Name2', 'Name3', 'Name4', 'Name5']


what is the solution if I want to have my "Shader0"  new name is "Name1"

Thank You very mutch!!!


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

denis hoffmann

unread,
Feb 23, 2017, 2:26:43 PM2/23/17
to Python Programming for Autodesk Maya
Thank you very mutch, you are my hero!

import maya.cmds as cmds

ShaderNames = cmds.ls ('phong*',  mat=True)

NewNames = ('Name1', 'Name2','Name3','Name4','Name5',)

for i in xrange(len(ShaderNames)):
    cmds.rename (ShaderNames[i] , NewNames[i])

That is my final resoult.
Reply all
Reply to author
Forward
0 new messages