waller99

Model Builder/Python Issue - <type 'exceptions.IndexError'>: list index out of range

Discussion created by waller99 on Jun 26, 2013
Latest reply on Jun 27, 2013 by waller99
I am a "rookie" at python and I incorporated a simple python script into model builder. My model runs without issues but when it gets to the python script, I get this error.

<type 'exceptions.IndexError'>: list index out of range


Below is my python file. Any help would be greatly appreciated. Thanks.

import arcpy
import os
import glob

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyr_region = arcpy.mapping.ListLayers(mxd, "GOM Regions")[0]
lyr_pro = arcpy.mapping.ListLayers(mxd, "Protraction Areas")[0]
lyr_APC = arcpy.mapping.ListLayers(mxd, "APC Active Leases")[0]
lyr_Blk = arcpy.mapping.ListLayers(mxd, "GOM Blocks")[0]
lyr_Bid = arcpy.mapping.ListLayers(mxd, "Tracts Receiving Bids")[0]

for name in glob.glob('C:\Users\dke610\Desktop\GoM\Sale*'):
    
    if name == 'C:\Users\dke610\Desktop\GoM\SaleWGM.xlsx':
        lyr_region.definitionQuery = "MMS_PLAN_A = 'WGM'"
        lyr_pro.definitionQuery = "REGION = 'WGOM'"
        lyr_APC.definitionQuery = "PLANAREA = 'W'"
        lyr_Blk.definitionQuery = "REGION0712 = 'W'"
        lyr_Bid.showLabels = False
        df.extent = lyr_Blk.getSelectedExtent()
        df.scale *= 1

    else:
        lyr_region.definitionQuery = "MMS_PLAN_A = 'CGM'"
        lyr_pro.definitionQuery = "REGION = 'CGOM'"
        lyr_APC.definitionQuery = "PLANAREA = 'C'"
        lyr_Blk.definitionQuery = "REGION0712 = 'C'"
        lyr_Bid.showLabels = False
        df.extent = lyr_Blk.getSelectedExtent()
        df.scale *= 1


arcpy.RefreshActiveView()        
del mxd

Outcomes