This line
for pFrame in arcpy.mapping.ListDataFrames(mxd, "t*"):
should be
for pFrame in dataframes:
since you already created a list of dataframes in the line before it.
Fixed that line and re-imported it into ArcToolbox. It ran, but the shapefile is completely empty. No polygons or table data. So disappointing.
Hi Heather,
Take a close look at this line. See if you can figure out what the issue is.
if pFrame.name.lower == "Strip":
Looking at ListDataFrames—Help | ArcGIS for Desktop and then DataFrame—Help | ArcGIS for Desktop , it looks like I should just change it to if pFrame.name == "Strip":. Did that and it opens the first layer, then tries to add the extent to the index, then fails.
Creating the new Map Index shapefile
Opening map document Z:\Projects\60132\Maps\Strip Maps\Arc\0027-2016.mxd
Adding the extent of Z:\Projects\60132\Maps\Strip Maps\Arc\0027-2016.mxd to the index.
Failed script MapIndex...Traceback (most recent call last):
File "C:\Users\heather\Documents\ArcGIS\AddIns\npeihl-mapindextool-0da4e723ca4a\Map Index Toolbox.tbx#MapIndex.py", line 76, in <module>
NameError: name 'rows' is not definedFailed to execute (MapIndex).
Failed at Fri Sep 16 11:03:31 2016 (Elapsed Time: 4.23 seconds)
If I am counting correctly,
Line 75: rows = arcpy.InsertCursor(index, spatialRef)
Line 76: row = rows.newRow()
I went back to the original code, and it is not something I have modified.
Hi Heather,
I do not know why it is failing. Line 76 is the very last line where the rows variable is deleted.
Perhaps we don't need to instantiate the InsertCursor on every iteration of the loop. You could try moving the creation of the rows InsertCursor out of the dataframes loop (perhaps directly under the creation of the index variable). You would just need to make sure the del rows line at the end is at the same indentation level as the creation of the InsertCusor.
But that doesn't explain why your code is failing, so I really don't know if it'll work. Welcome to the world of programming.
So, I moved it just like you suggested, and things seemed to work. It opened up all the files and added the extent to the index. However, after the last file, I got the same exact error, so it acted like it didn't finish. However, upon looking at the shapefile, it is all there. Crazy, but it works!
Thank you!