I keep getting the error <type 'exceptions.IndexError'>: list index out of range in my script tool. The tool works when i hardcode the list of layers in (see commmented line) but fails when i read in the parameters (1) from a value list filter set up in the script tool.
The value list filter contains the same strings as the hardcoded line commented out below. The only difference I see is that the individual elements in lyrList are wrapped in single quotes when read in from the parameter value list and are not when read in from the line of code below.
(i tested this by saving the values of both to a text file to check)
a screen capture of the script tool parameter is attached.
Any suggestions.
Thanks,
Brent
#Specify the map document and the data frame
mxd = arcpy.mapping.MapDocument(r"C:\data\WebPrintTool_v1\test.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
# Get the Parameters (Feature Set drawn on by user)
areaOfInterest = arcpy.GetParameterAsText(0)
# Get the Parameters (value list filter of layer names - type string)
lyrList = arcpy.GetParameterAsText(1).split(";")
# Get the Parameters (output path to pdf)
outPath = arcpy.GetParameterAsText(2).replace("\\",os.sep)
# Get the feature Set to describe
desc = arcpy.Describe(areaOfInterest)
finalPdf = arcpy.mapping.PDFDocumentCreate(outPath)
# Specify the Area of Interest
df.extent = arcpy.Extent(desc.extent.XMin, desc.extent.YMin, desc.extent.XMax, desc.extent.YMax)
### Turn on visibility for each theme and export the page (this works)##lyrList = ["BEDROCK GEOLOGY", "DRIFT THICKNESS", "SURFICIAL GEOLOGY", "TEST HOLE"]
for lyrName in lyrList:
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
lyr.visible = True
#Export each theme to a temporary PDF and append to the final PDF
tmpPdf = os.path.dirname(outPath) + lyrName + "_temp.pdf"
if os.path.exists(tmpPdf):
os.remove(tmpPdf)
arcpy.mapping.ExportToPDF(mxd, tmpPdf)
finalPdf.appendPages(tmpPdf)
#Turn off layer visibility and clean up for next pass through the loop
lyr.visible = False
del lyr, tmpPdf
del mxd, df, finalPdf