Hi Chris, That was my initial thought as well, but it is not consistent with what is happening. In the example I provided, for instance, there are two problems:
1. Attempting to access element 0 when length is 0 returns None, as opposed to a swig object for an MDagPath (as was the case for any OOB index > 0) 2. After accessing elements that I would expect to be out of bounds, the array's length never changes. If you print testArray.length() again it is still 0. Furthermore, consider the following example: import maya.OpenMaya as OM # Create an empty MDagPathArray testArray = OM.MDagPathArray() # Populate the array with some data foo = OM.MDagPath() testArray.append(foo) testArray.append(foo) # Confirm that that the array is length 2 print testArray.length() You will of course see the output: 2. Now do this: bar = OM.MDagPath() # inserting into an existing index works fine testArray.insert(bar, 1) print testArray.length() You see 3. Now do this: # inserting immediately after the final index also works fine testArray.insert(bar, 3) print testArray.length() You see 4. *This, however, will consistently crash Maya (at least for me, 2010 on OSX):* # however, inserting two or more indices after the final valid index crashes Maya testArray.insert(bar, 5) print testArray.length() Wrapping the final example in a try/except still simply crashes so I have no idea what the actual problem is. On Tue, Sep 29, 2009 at 5:29 PM, chrisg <[email protected]> wrote: > > That's because it isn't out of bounds, it's a sparse array that > resizes automatically. > > > On Sep 29, 6:03 pm, Adam Mechtley <[email protected]> wrote: > > I've run into something a little confusing I am hoping someone here can > > clarify. Try this: > > > > import maya.OpenMaya as OM > > > > testArray = OM.MDagPathArray() > > print testArray.length() > > > > You will of course get: > > > > 0 > > > > Now try this: > > > > print testArray[0] > > > > You will of course get: > > > > None > > > > However, even though this array is empty, if you do this: > > > > print testArray[1] > > > > or this: > > > > print testArray[100] > > > > you will get something like this: > > > > <maya.OpenMaya.MDagPath; proxy of <Swig Object of type 'MDagPath *' at > 0x8> > > > > > > > > The reason this is causing me problems is because I am wanting to catch > an > > index out of bounds exception for an MDagPathArray in a plugin. However, > > Maya Python does not seem to mind that I am trying to access an index > that > > is out of bounds. Any ideas? > > > --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/python_inside_maya -~----------~----~----~----~------~----~------~--~---
