POST
|
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
... View more
01-20-2011
03:00 AM
|
0
|
1
|
2037
|
POST
|
I am working on a tool that will eventually be used to create a pdf from multiple mxds (a thematic map book). The tool will run a a server geoprocessing service. The basic workflow is below - user draws a polygon (feature set) - for each mxd... zoom to extent of the feature set and export layout view of the mxd to pdf. - compile into one pdf. how do I access the values from the extent of the "feature set" so I can modify the data frame extent in each mxd? Thanks
... View more
10-22-2010
05:12 AM
|
0
|
5
|
3790
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|