<?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 Re: Model Builder/Python Issue - &amp;lt;type 'exceptions.IndexError'&amp;gt;: list index out of ra in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/model-builder-python-issue-amp-lt-type-exceptions/m-p/657158#M51129</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;lyr_Bid = arcpy.mapping.ListLayers(mxd, "Tracts Receiving Bids")[0]
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This layer is created in the model. I removed that line out of my script and it ran successfully. I suppose the issue is that the "Tracts Receiving Bids" layer isn't displayed until the whole model, script and all, runs completely. Is there a way to display that layer after it is created? This is how it works when running it within model builder.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 03:48:55 GMT</pubDate>
    <dc:creator>DustinWaller1</dc:creator>
    <dc:date>2021-12-12T03:48:55Z</dc:date>
    <item>
      <title>Model Builder/Python Issue - &amp;lt;type 'exceptions.IndexError'&amp;gt;: list index out of range</title>
      <link>https://community.esri.com/t5/python-questions/model-builder-python-issue-amp-lt-type-exceptions/m-p/657154#M51125</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am a "rookie" at python and I incorporated a simple python script into model builder. My model runs without issues but when it gets to the python script, I get this error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;type 'exceptions.IndexError'&amp;gt;: list index out of range&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Below is my python file. Any help would be greatly appreciated. Thanks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy
import os
import glob

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyr_region = arcpy.mapping.ListLayers(mxd, "GOM Regions")[0]
lyr_pro = arcpy.mapping.ListLayers(mxd, "Protraction Areas")[0]
lyr_APC = arcpy.mapping.ListLayers(mxd, "APC Active Leases")[0]
lyr_Blk = arcpy.mapping.ListLayers(mxd, "GOM Blocks")[0]
lyr_Bid = arcpy.mapping.ListLayers(mxd, "Tracts Receiving Bids")[0]

for name in glob.glob('C:\Users\dke610\Desktop\GoM\Sale*'):
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; if name == 'C:\Users\dke610\Desktop\GoM\SaleWGM.xlsx':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr_region.definitionQuery = "MMS_PLAN_A = 'WGM'"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr_pro.definitionQuery = "REGION = 'WGOM'"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr_APC.definitionQuery = "PLANAREA = 'W'"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr_Blk.definitionQuery = "REGION0712 = 'W'"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr_Bid.showLabels = False
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = lyr_Blk.getSelectedExtent()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.scale *= 1

&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr_region.definitionQuery = "MMS_PLAN_A = 'CGM'"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr_pro.definitionQuery = "REGION = 'CGOM'"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr_APC.definitionQuery = "PLANAREA = 'C'"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr_Blk.definitionQuery = "REGION0712 = 'C'"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr_Bid.showLabels = False
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = lyr_Blk.getSelectedExtent()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.scale *= 1


arcpy.RefreshActiveView()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
del mxd&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jun 2013 20:05:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/model-builder-python-issue-amp-lt-type-exceptions/m-p/657154#M51125</guid>
      <dc:creator>DustinWaller1</dc:creator>
      <dc:date>2013-06-26T20:05:19Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder/Python Issue - &lt;type 'exceptions.IndexError'&gt;: list index out of ra</title>
      <link>https://community.esri.com/t5/python-questions/model-builder-python-issue-amp-lt-type-exceptions/m-p/657155#M51126</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'd wager it was because one of those layers you are trying to reference do not exist in the mxd.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jun 2013 20:46:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/model-builder-python-issue-amp-lt-type-exceptions/m-p/657155#M51126</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-06-26T20:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder/Python Issue - &lt;type 'exceptions.IndexError'&gt;: list index out of ra</title>
      <link>https://community.esri.com/t5/python-questions/model-builder-python-issue-amp-lt-type-exceptions/m-p/657156#M51127</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I would say that I agree but the model runs from the Model Builder Edit window. I only errors out when I double click on the model in the toolbox to run it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jun 2013 11:20:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/model-builder-python-issue-amp-lt-type-exceptions/m-p/657156#M51127</guid>
      <dc:creator>DustinWaller1</dc:creator>
      <dc:date>2013-06-27T11:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder/Python Issue - &lt;type 'exceptions.IndexError'&gt;: list index out of ra</title>
      <link>https://community.esri.com/t5/python-questions/model-builder-python-issue-amp-lt-type-exceptions/m-p/657157#M51128</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you are running it out of process you may have problems with the 'current' keyword for your mxd, but that should give you a different error. Are any of those layers created within the model you are running? Or do they all exist in the mxd prior to the model running?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jun 2013 12:18:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/model-builder-python-issue-amp-lt-type-exceptions/m-p/657157#M51128</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-06-27T12:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder/Python Issue - &lt;type 'exceptions.IndexError'&gt;: list index out of ra</title>
      <link>https://community.esri.com/t5/python-questions/model-builder-python-issue-amp-lt-type-exceptions/m-p/657158#M51129</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;lyr_Bid = arcpy.mapping.ListLayers(mxd, "Tracts Receiving Bids")[0]
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This layer is created in the model. I removed that line out of my script and it ran successfully. I suppose the issue is that the "Tracts Receiving Bids" layer isn't displayed until the whole model, script and all, runs completely. Is there a way to display that layer after it is created? This is how it works when running it within model builder.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:48:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/model-builder-python-issue-amp-lt-type-exceptions/m-p/657158#M51129</guid>
      <dc:creator>DustinWaller1</dc:creator>
      <dc:date>2021-12-12T03:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder/Python Issue - &lt;type 'exceptions.IndexError'&gt;: list index out of ra</title>
      <link>https://community.esri.com/t5/python-questions/model-builder-python-issue-amp-lt-type-exceptions/m-p/657159#M51130</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;lyr_Bid = arcpy.mapping.ListLayers(mxd, "Tracts Receiving Bids")[0]
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;This layer is created in the model. I removed that line out of my script and it ran successfully. I suppose the issue is that the "Tracts Receiving Bids" layer isn't displayed until the whole model, script and all, runs completely. Is there a way to display that layer after it is created? This is how it works when running it within model builder.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you only need the layer for the model you can use the Make Feature Layer tool and reference it in memory. If you need to add it to the map you can then use the Add Layer function in the mapping module after processing.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:48:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/model-builder-python-issue-amp-lt-type-exceptions/m-p/657159#M51130</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-12T03:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder/Python Issue - &lt;type 'exceptions.IndexError'&gt;: list index out of ra</title>
      <link>https://community.esri.com/t5/python-questions/model-builder-python-issue-amp-lt-type-exceptions/m-p/657160#M51131</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for your help. It is appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jun 2013 13:32:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/model-builder-python-issue-amp-lt-type-exceptions/m-p/657160#M51131</guid>
      <dc:creator>DustinWaller1</dc:creator>
      <dc:date>2013-06-27T13:32:43Z</dc:date>
    </item>
  </channel>
</rss>

