<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic &amp;lt;type 'exceptions.IndexError'&amp;gt;: list index out of range in Mapping Questions</title>
    <link>https://community.esri.com/t5/mapping-questions/lt-type-exceptions-indexerror-gt-list-index-out-of/m-p/518530#M5544</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I keep getting the error &amp;lt;type 'exceptions.IndexError'&amp;gt;: 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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(i tested this by saving the values of both to a text file to check)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;a screen capture of the script tool parameter is attached.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any suggestions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Brent&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Specify the map document and the data frame&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument(r"C:\data\WebPrintTool_v1\test.mxd")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get the Parameters (Feature Set drawn on by user)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;areaOfInterest = arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get the Parameters (value list filter of layer names - type string)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lyrList = arcpy.GetParameterAsText(1).split(";")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get the Parameters (output path to pdf)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outPath = arcpy.GetParameterAsText(2).replace("\\",os.sep)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get the feature Set to describe&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;desc = arcpy.Describe(areaOfInterest)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;finalPdf = arcpy.mapping.PDFDocumentCreate(outPath)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Specify the Area of Interest&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df.extent = arcpy.Extent(desc.extent.XMin, desc.extent.YMin, desc.extent.XMax, desc.extent.YMax)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;### Turn on visibility for each theme and export the page (this works)##lyrList = ["BEDROCK GEOLOGY", "DRIFT THICKNESS", "SURFICIAL GEOLOGY", "TEST HOLE"]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for lyrName in lyrList:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; lyr.visible = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; #Export each theme to a temporary PDF and append to the final PDF&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; tmpPdf = os.path.dirname(outPath) + lyrName + "_temp.pdf"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; if os.path.exists(tmpPdf):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; os.remove(tmpPdf)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; finalPdf.appendPages(tmpPdf)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; #Turn off layer visibility and clean up for next pass through the loop&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; lyr.visible = False&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; del lyr, tmpPdf&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;del mxd, df, finalPdf&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 20 Jan 2011 11:00:29 GMT</pubDate>
    <dc:creator>BrentTucker</dc:creator>
    <dc:date>2011-01-20T11:00:29Z</dc:date>
    <item>
      <title>&lt;type 'exceptions.IndexError'&gt;: list index out of range</title>
      <link>https://community.esri.com/t5/mapping-questions/lt-type-exceptions-indexerror-gt-list-index-out-of/m-p/518530#M5544</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I keep getting the error &amp;lt;type 'exceptions.IndexError'&amp;gt;: 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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(i tested this by saving the values of both to a text file to check)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;a screen capture of the script tool parameter is attached.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any suggestions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Brent&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Specify the map document and the data frame&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument(r"C:\data\WebPrintTool_v1\test.mxd")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get the Parameters (Feature Set drawn on by user)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;areaOfInterest = arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get the Parameters (value list filter of layer names - type string)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lyrList = arcpy.GetParameterAsText(1).split(";")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get the Parameters (output path to pdf)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outPath = arcpy.GetParameterAsText(2).replace("\\",os.sep)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get the feature Set to describe&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;desc = arcpy.Describe(areaOfInterest)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;finalPdf = arcpy.mapping.PDFDocumentCreate(outPath)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Specify the Area of Interest&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df.extent = arcpy.Extent(desc.extent.XMin, desc.extent.YMin, desc.extent.XMax, desc.extent.YMax)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;### Turn on visibility for each theme and export the page (this works)##lyrList = ["BEDROCK GEOLOGY", "DRIFT THICKNESS", "SURFICIAL GEOLOGY", "TEST HOLE"]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for lyrName in lyrList:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; lyr.visible = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; #Export each theme to a temporary PDF and append to the final PDF&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; tmpPdf = os.path.dirname(outPath) + lyrName + "_temp.pdf"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; if os.path.exists(tmpPdf):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; os.remove(tmpPdf)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.mapping.ExportToPDF(mxd, tmpPdf)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; finalPdf.appendPages(tmpPdf)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; #Turn off layer visibility and clean up for next pass through the loop&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; lyr.visible = False&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; del lyr, tmpPdf&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;del mxd, df, finalPdf&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jan 2011 11:00:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/lt-type-exceptions-indexerror-gt-list-index-out-of/m-p/518530#M5544</guid>
      <dc:creator>BrentTucker</dc:creator>
      <dc:date>2011-01-20T11:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: &lt;type 'exceptions.IndexError'&gt;: list index out of range</title>
      <link>https://community.esri.com/t5/mapping-questions/lt-type-exceptions-indexerror-gt-list-index-out-of/m-p/518531#M5545</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello Brent,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried to reproduce on my 10.0 SP1 machine.&amp;nbsp; I set up everything like you did and it all worked.&amp;nbsp; Here is my simplified code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lyrList = arcpy.GetParameterAsText(0).split(";")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument(r"c:\temp\brent\brent.mxd")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for lyrName in lyrList:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; lyr = arcpy.mapping.ListLayers(mxd, lyrName)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; lyr.visible = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; arcpy.mapping.ExportToPDF(mxd, r"c:\temp\brent\\" + lyrName + ".pdf")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; lyr.visible = False&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is it possible you have extra spaces in your value list values?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd be more than happy to send you my toolbox/scripts, etc if that helps.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;Jeff (&lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:jbarrette@esri.com"&gt;jbarrette@esri.com&lt;/A&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Jan 2011 14:02:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/lt-type-exceptions-indexerror-gt-list-index-out-of/m-p/518531#M5545</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2011-01-21T14:02:18Z</dc:date>
    </item>
  </channel>
</rss>

