<?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: Python - How to make a 2D array, or an array of arrays? in Maya Programming Forum</title>
    <link>https://forums.autodesk.com/t5/maya-programming-forum/python-how-to-make-a-2d-array-or-an-array-of-arrays/m-p/8701476#M8053</link>
    <description>&lt;P&gt;Yes, that works.&lt;/P&gt;</description>
    <pubDate>Tue, 02 Apr 2019 14:20:22 GMT</pubDate>
    <dc:creator>RFlannery1</dc:creator>
    <dc:date>2019-04-02T14:20:22Z</dc:date>
    <item>
      <title>Python - How to make a 2D array, or an array of arrays?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/python-how-to-make-a-2d-array-or-an-array-of-arrays/m-p/8691755#M8050</link>
      <description>&lt;P&gt;I have a scene with a number of group nodes. Each group node contains a unique number of individual meshes.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I would like to create a python script that takes the selected groups, creates a joint for each of the meshes inside the group, and appends the newly created joint to an array.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Let's say...&lt;BR /&gt;myJoints is the name of the joint array&lt;BR /&gt;and...&lt;BR /&gt;group1 contains 6 meshes&lt;BR /&gt;group2 contains 13 meshes&lt;BR /&gt;group3 contains 8 meshes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How would I go about appending the newly created joints to the array? Is there such a thing as a 2D array? Or an array of arrays?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Normally I might use something like:&lt;BR /&gt;myJoints.append(newJoint)&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;However, in this case I would want to have an array that holds multiple arrays, so I'd be inclined to do something like this, but it doesn't seem to work:&lt;BR /&gt;myJoints[i].append(newJoint)&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2019 18:18:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/python-how-to-make-a-2d-array-or-an-array-of-arrays/m-p/8691755#M8050</guid>
      <dc:creator>dkrelina</dc:creator>
      <dc:date>2019-03-28T18:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: Python - How to make a 2D array, or an array of arrays?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/python-how-to-make-a-2d-array-or-an-array-of-arrays/m-p/8694346#M8051</link>
      <description>&lt;P&gt;The last line of code you posted should work.&amp;nbsp; Without seeing the rest of your code, I can't be sure, but I suspect that you just need to initialize a blank list for each group before adding to it.&amp;nbsp; For example, the following code will give an error:&lt;/P&gt;
&lt;PRE&gt;myJoints = []&lt;BR /&gt;for i, group in enumerate(selectedGroups):
    for mesh in group:&lt;BR /&gt;        newJoint = makeNewJoint()&lt;BR /&gt;        myJoints[i].append(newJoint)&lt;/PRE&gt;
&lt;P&gt;But the error can be fixed:&lt;/P&gt;
&lt;PRE&gt;myJoints = []
for group in selectedGroups:&lt;BR /&gt;    jointGroup = []
    for mesh in group:
        newJoint = makeNewJoint()
        jointGroup.append(newJoint)&lt;BR /&gt;    myJoints.append(jointGroup)&lt;/PRE&gt;
&lt;P&gt;As a separate note, I would recommend storing the data in a dict rather than in a list of lists.&amp;nbsp; That way you can refer to each group by name instead of having to remember "groupA is index 0, groupB is index 1, etc.".&amp;nbsp; Something like the following:&lt;/P&gt;
&lt;PRE&gt;myJoints = {}
for group in selectedGroups:
    myJoints[group] = []&lt;BR /&gt;    for mesh in group:&lt;BR /&gt;        newJoint = makeNewJoint()&lt;BR /&gt;        myJoints[group].append(newJoint)&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Mar 2019 17:15:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/python-how-to-make-a-2d-array-or-an-array-of-arrays/m-p/8694346#M8051</guid>
      <dc:creator>RFlannery1</dc:creator>
      <dc:date>2019-03-29T17:15:20Z</dc:date>
    </item>
    <item>
      <title>Re: Python - How to make a 2D array, or an array of arrays?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/python-how-to-make-a-2d-array-or-an-array-of-arrays/m-p/8701284#M8052</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1267610"&gt;@RFlannery1&lt;/a&gt;! That worked well. In my case, the list of lists route did the trick since I don't need to refer to each group by name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I query or edit an individual joint in this list of lists? Can I use the name of the array followed by two sets of square brackets? ex. myJoints[i][j] ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Will this work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;# set translateX of joint 2 in group 0
cmds.setAttr(myJoints[0][2] + '.translateX', 20 )&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Apr 2019 13:18:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/python-how-to-make-a-2d-array-or-an-array-of-arrays/m-p/8701284#M8052</guid>
      <dc:creator>dkrelina</dc:creator>
      <dc:date>2019-04-02T13:18:54Z</dc:date>
    </item>
    <item>
      <title>Re: Python - How to make a 2D array, or an array of arrays?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/python-how-to-make-a-2d-array-or-an-array-of-arrays/m-p/8701476#M8053</link>
      <description>&lt;P&gt;Yes, that works.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2019 14:20:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/python-how-to-make-a-2d-array-or-an-array-of-arrays/m-p/8701476#M8053</guid>
      <dc:creator>RFlannery1</dc:creator>
      <dc:date>2019-04-02T14:20:22Z</dc:date>
    </item>
  </channel>
</rss>

