AnsweredAssumed Answered

IndexError: list out of range

Question asked by bgale88 on Feb 24, 2012
Latest reply on Feb 27, 2012 by bgale88
Hello,

My code works fine when run as a script, but errors when run as a geoprocessing tool. The only changes I made were the env.workspace and newYear_Month variable. I cannot seem to debug this, so any and all help will be greatly appreciated.

This is my code:
mxd = arcpy.mapping.MapDocument("CURRENT") #Step 9b: Join CountyParcel.APN to ParcelOwnership_NEW.PARCEL_APN arcpy.AddJoin_management("CountyParcel", "APN", "lfgdb.SDE.ParcelOwnership_NEW", "PARCEL_APN") #Step 9C: Compare city owned parcels to CityOwnedProperty  arcpy.SelectLayerByAttribute_management("CountyParcel", "NEW_SELECTION", "lfgdb.SDE.ParcelOwnership_NEW.firstName = 'CITY OF LAKE FOREST' OR lfgdb.SDE.ParcelOwnership_NEW.firstName = 'CITY OF LAKE FOREST REDEV AGCY'") arcpy.SelectLayerByLocation_management("lfgdb.SDE.CityOwnedProperty", "HAVE_THEIR_CENTER_IN", "CountyParcel", "", "NEW_SELECTION") CountyParcelFC = arcpy.mapping.ListLayers(mxd, "CountyParcel")[0] CountyParcelFC.visible = False arcpy.RefreshTOC() arcpy.RefreshActiveView() arcpy.SelectLayerByLocation_management("lfgdb.SDE.CityOwnedProperty", "", "", "", "SWITCH_SELECTION") #Create new city owned discrepancy layer. arcpy.env.workspace = r"Q:\Applications\GIS\Maps\Management Services\Parcel_Comparison_2012\OwnershipDMP_NotCity.gdb" newYear_Month = arcpy.GetParameterAsText(0) arcpy.Select_analysis("lfgdb.SDE.CityOwnedProperty", "OwnershipDMP_NotCity_" + newYear_Month) CityOwnedPropertyFC = arcpy.mapping.ListLayers(mxd, "lfgdb.SDE.CityOwnedProperty")[0] CityOwnedPropertyFC.visible = False arcpy.RefreshTOC() arcpy.RefreshActiveView() print "INFORM DOUG OF NEW 'OwnershipDMP_NotCity' FEATURE CLASS" CityOwnedPropertyFC.visible = True CountyParcelFC.visible = True arcpy.RefreshTOC() arcpy.RefreshActiveView() arcpy.SelectLayerByAttribute_management("CountyParcel", "CLEAR_SELECTION") arcpy.SelectLayerByAttribute_management("lfgdb.SDE.CityOwnedProperty", "CLEAR_SELECTION") df = arcpy.mapping.ListDataFrames(mxd)[0] removeLayer = arcpy.mapping.ListLayers(mxd, "OwnershipDMP_NotCity_" + newYear_Month)[0] arcpy.mapping.RemoveLayer(df, removeLayer) arcpy.RemoveJoin_management("CountyParcel", "lfgdb.SDE.ParcelOwnership_NEW") arcpy.mapping.MapDocument.save(mxd)

The bolded line is where I suspect the problem to be.

This is my error message:
"<type 'exceptions.IndexError'>: list index out of range"

Please help! Thank you!

Outcomes