<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Rename object using for loop in Maya Programming Forum</title>
    <link>https://forums.autodesk.com/t5/maya-programming-forum/rename-object-using-for-loop/m-p/9708363#M5501</link>
    <description>&lt;P&gt;There are many, many ways in which you could achieve this - from almost hardcoded, to something potentially illegible, so I would say it would actually be a great learning exercise.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;# Provide variables for grouped naming segments
side = 'left'
descriptors = [
    'Thumb',
    'Pointer',
    'Middle',
    'Ring',
    'Pinky',
]
identifiers = [
    '_base_CTRL',
    '_01_CTRL',
    '_02_CTRL',
]

# Get the selection and break it into groups of 3
selection = mc.ls(sl=True)
sel_chunk = [
    selection[i:i + 3]
    for i in range(0, len(selection), 3)
]

# Iterate the selection groups and descriptor for that group ('Thumb')
for sel_grp, desc in zip(sel_chunk, descriptors):

    # Iterate each item in the selection group along with an index
    for i, name in enumerate(sel_grp):

        # Construct the name. 
        # The modulus operator is very convenient (not to be confused with old-style string formatting).
        new_name = side + desc + identifiers[i % 3]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Python enumeration:&lt;/P&gt;&lt;P&gt;&lt;A href="https://book.pythontips.com/en/latest/enumerate.html" target="_blank"&gt;https://book.pythontips.com/en/latest/enumerate.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Python modulus operator:&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.freecodecamp.org/news/the-python-modulo-operator-what-does-the-symbol-mean-in-python-solved/" target="_blank"&gt;https://www.freecodecamp.org/news/the-python-modulo-operator-what-does-the-symbol-mean-in-python-solved/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are many other ways to do this, but this seemed to closer to the direction you were heading.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Aug 2020 14:29:17 GMT</pubDate>
    <dc:creator>lee.dunham</dc:creator>
    <dc:date>2020-08-24T14:29:17Z</dc:date>
    <item>
      <title>Rename object using for loop</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/rename-object-using-for-loop/m-p/9706490#M5500</link>
      <description>&lt;P&gt;I have a list of objects which I want to rename. But I want each object to be renamed differently. Image attached as an example.&lt;/P&gt;&lt;P&gt;This is what I did so far but its not working as I want.&lt;/P&gt;&lt;P&gt;Can anyone help me please&lt;/P&gt;&lt;P&gt;Thanks in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;lGrpSel = cmds.ls(leftFingers)&lt;/P&gt;&lt;P&gt;chunk_size = 3&lt;/P&gt;&lt;P&gt;leftChunks = [lGrpSel[i:i + chunk_size] for i in range(0, len(lGrpSel), chunk_size)]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;side = 'left'&lt;BR /&gt;thumb = 'Thumb'&lt;BR /&gt;pointer = 'Pointer'&lt;BR /&gt;middle = 'Middle'&lt;BR /&gt;ring = 'Ring'&lt;BR /&gt;pinky = 'Pinky'&lt;BR /&gt;order = ['Base', '01', '02']&lt;BR /&gt;objType = 'CTRL'&lt;BR /&gt;spacer = '_'&lt;BR /&gt;&lt;BR /&gt;for f in leftChunks:&lt;BR /&gt;for i in range(0, len(f), 1):&lt;BR /&gt;cmds.rename(f[i], side + thumb + spacer + order[i] + spacer + objType)&lt;BR /&gt;cmds.rename(f[i], side + pointer + spacer + order[i] + spacer + objType)&lt;BR /&gt;cmds.rename(f[i], side + middle + spacer + order[i] + spacer + objType)&lt;BR /&gt;cmds.rename(f[i], side + ring + spacer + order[i] + spacer + objType)&lt;BR /&gt;cmds.rename(f[i], side + pinky + spacer + order[i] + spacer + objType)&lt;/P&gt;</description>
      <pubDate>Sun, 23 Aug 2020 07:57:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/rename-object-using-for-loop/m-p/9706490#M5500</guid>
      <dc:creator>danispag</dc:creator>
      <dc:date>2020-08-23T07:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: Rename object using for loop</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/rename-object-using-for-loop/m-p/9708363#M5501</link>
      <description>&lt;P&gt;There are many, many ways in which you could achieve this - from almost hardcoded, to something potentially illegible, so I would say it would actually be a great learning exercise.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;# Provide variables for grouped naming segments
side = 'left'
descriptors = [
    'Thumb',
    'Pointer',
    'Middle',
    'Ring',
    'Pinky',
]
identifiers = [
    '_base_CTRL',
    '_01_CTRL',
    '_02_CTRL',
]

# Get the selection and break it into groups of 3
selection = mc.ls(sl=True)
sel_chunk = [
    selection[i:i + 3]
    for i in range(0, len(selection), 3)
]

# Iterate the selection groups and descriptor for that group ('Thumb')
for sel_grp, desc in zip(sel_chunk, descriptors):

    # Iterate each item in the selection group along with an index
    for i, name in enumerate(sel_grp):

        # Construct the name. 
        # The modulus operator is very convenient (not to be confused with old-style string formatting).
        new_name = side + desc + identifiers[i % 3]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Python enumeration:&lt;/P&gt;&lt;P&gt;&lt;A href="https://book.pythontips.com/en/latest/enumerate.html" target="_blank"&gt;https://book.pythontips.com/en/latest/enumerate.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Python modulus operator:&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.freecodecamp.org/news/the-python-modulo-operator-what-does-the-symbol-mean-in-python-solved/" target="_blank"&gt;https://www.freecodecamp.org/news/the-python-modulo-operator-what-does-the-symbol-mean-in-python-solved/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are many other ways to do this, but this seemed to closer to the direction you were heading.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2020 14:29:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/rename-object-using-for-loop/m-p/9708363#M5501</guid>
      <dc:creator>lee.dunham</dc:creator>
      <dc:date>2020-08-24T14:29:17Z</dc:date>
    </item>
    <item>
      <title>Re: Rename object using for loop</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/rename-object-using-for-loop/m-p/9708500#M5502</link>
      <description>&lt;P&gt;Amazing that worked perfectly :). Thank you so much&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2020 15:14:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/rename-object-using-for-loop/m-p/9708500#M5502</guid>
      <dc:creator>danielblaze</dc:creator>
      <dc:date>2020-08-24T15:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: Rename object using for loop</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/rename-object-using-for-loop/m-p/9708532#M5503</link>
      <description>&lt;P&gt;No problem&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2020 15:27:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/rename-object-using-for-loop/m-p/9708532#M5503</guid>
      <dc:creator>lee.dunham</dc:creator>
      <dc:date>2020-08-24T15:27:55Z</dc:date>
    </item>
  </channel>
</rss>

