I am new to Python and encountered an issue while trying to write a script.

I am receiving a list index out of range error while trying to read the criminal activity layer file.

Any help would be appreciated.


import arcpy

# Data Layers in Secondary Map Document
mxd2 = arcpy.mapping.MapDocument(r"C:/Users/jeffande1966/Desktop/Home and Work/College/GEOG485/Lesson 3/Data.mxd")
df2 = arcpy.mapping.ListDataFrames(mxd2, "Data")[0]
print df2
addLayer = arcpy.mapping.ListLayers(mxd2, "Criminal Activity", df2)[0]
addLayer2 = arcpy.mapping.ListLayers(mxd2, "Traffic Violations", df2)[0]
df3 = arcpy.mapping.ListDataFrames(mxd2, "Roads")[0]
print df3
addLayer3 = arcpy.mapping.ListLayers(mxd2, "Roads", df3)[0]

# Map Document Layers to be Added To
mxd = arcpy.mapping.MapDocument(r"C:/Users/jeffande1966/Desktop/Home and Work/College/GEOG485/Lesson 3/Patrol Zones.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Police Patrol Zones")[0]
print df
arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE")

# Text Element
textelm = "Jeff Anderson Project 3" 
textelm = arcpy.mapping.ListLayoutElements(mxd)[0]
print textelm

for df in arcpy.mapping.ListDataFrames(mxd):
    mxd.activeView = df.name
    mxd.title = df.name
    mxd.saveACopy(r"C:/Users/jeffande1966/Desktop/Home and Work/College/GEOG485/Final Project//" + df.name + ".mxd")
    print df

for lyr in arcpy.mapping.ListLayers(mxd):
    print lyr.name
for textelm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
  if textelm.text == "Jeff Anderson Project 3":
    textelm.text = "Jeff Anderson Final Project"
    print textelm

arcpy.mapping.ExportToPDF(mxd, r"C:/Users/jeffande1966/Desktop/Home and Work/College/GEOG485/Final Project/Final Project.pdf")
5 Years
Discussion Span
Last Post by pyTony

You forgot the exact error message. Any of those lines with [0] would produce error if the list would be empty.

Edited by pyTony: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.