If your goal is to rename each item in the selection to an incrementally
new name, you probably want to specify each original name as you do it:
import maya.cmds as cmds
def renameFun ():
mySel = cmds.ls(selection=True)
newName = "Test_Name"
for i, orig in enumerate(mySel):
cmds.rename(orig, "%s_%d" % (newName, i))
"enumerate" is convenient way of automatically getting an incremented
counter in addition to each item of your list. It would be equivalent do
doing something like:
i = 0
for orig in mySel:
...
i += 1
On Mon, Jan 6, 2014 at 11:57 AM, <[email protected]> wrote:
> Try this:
>
> import maya.cmds as cmds
>
> def renameFun ():
>
> for i in xrange ( len ( cmds.ls (selection = True) ) + 1 ):
> cmds.rename("Test_Name_%s" % i)
>
> return True
>
> # Python starts counting at zero so you will miss the last object without
> adding a one
> # range has been proven to show consistent memory drains, use xrange
> instead
> # That’s a string, not a digit you are adding into the name
> # Not sure why it would only ever rename one item, but hope this helps
> # Always return at least True, according to PEP8, but if you are new to
> python don’t worry about that just yet.
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/52c9e4c4.08eac20a.6b33.ffffbebf%40mx.google.com
> .
>
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1z9hw3yJ9NmBKKHZdR9dBu-UjuuXQzG%3DNRA-JpXemZRw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.