<?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: Issue with script in model in ModelBuilder Questions</title>
    <link>https://community.esri.com/t5/modelbuilder-questions/issue-with-script-in-model/m-p/869799#M2947</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;are results temporary by default?&lt;/P&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/executing-tools/using-geoprocessing-options-to-control-tool-execution.htm" title="http://desktop.arcgis.com/en/arcmap/latest/analyze/executing-tools/using-geoprocessing-options-to-control-tool-execution.htm"&gt;Using geoprocessing options to control tool execution—Help | ArcGIS for Desktop&lt;/A&gt;&lt;/P&gt;&lt;P&gt;picture??&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 02 Aug 2016 16:24:34 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2016-08-02T16:24:34Z</dc:date>
    <item>
      <title>Issue with script in model</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/issue-with-script-in-model/m-p/869798#M2946</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am working on a model and one of the steps executes a script (script is called AddLayerSitePolygon(2)). The purpose of the script is to:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;add a layer named "site_polygon"&lt;/LI&gt;&lt;LI&gt;rename the layer to "PROPOSED - site_polygon"&lt;/LI&gt;&lt;LI&gt;add a new layer named "site_polygon"&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;The end result being that 2 new layers are added to the TOC ("site_polygon" and "PROPOSED - site_polygon").&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I watch the model execute I can see that the script works as I see the 2 layers get added to the TOC, but then right after they are removed from the TOC.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Afterwards if I go ahead and run the script on it's own (outside of the model) it works as expected, the layers are added to the TOC and they stay there.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I cannot figure out why it is that when the script is run within the model that the layers get removed from the TOC?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is what the script looks like:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
##Reference the Current map document.
#Add site_polygon
mxd = arcpy.mapping.MapDocument("Current")
df = arcpy.mapping.ListDataFrames(mxd)[0]
NewLayer = arcpy.mapping.Layer("site_polygon.lyr")
arcpy.mapping.AddLayer(df, NewLayer, "AUTO_ARRANGE")
AddLayerSitePolygonResult = True
mxd.save()
#Rename site_polygon to "PROPOSED - site_polygon"
for lyr in arcpy.mapping.ListLayers(mxd):
 if lyr.name in ("site_polygon"):
&amp;nbsp; lyr.name = "PROPOSED - site_polygon"
mxd.save()
#Add site_polygon
df2 = arcpy.mapping.ListDataFrames(mxd)[0]
NewLayer2 = arcpy.mapping.Layer("site_polygon.lyr")
arcpy.mapping.AddLayer(df2, NewLayer2, "AUTO_ARRANGE")
AddLayerRenameSitePolygonResult = True
arcpy.SetParameter(0, AddLayerRenameSitePolygonResult)
mxd.save()
arcpy.RefreshTOC()
arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;P&gt;And here is a picture of where the script is in the model:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for any help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 10:50:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/issue-with-script-in-model/m-p/869798#M2946</guid>
      <dc:creator>ChrisHolmes</dc:creator>
      <dc:date>2021-12-12T10:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with script in model</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/issue-with-script-in-model/m-p/869799#M2947</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;are results temporary by default?&lt;/P&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/executing-tools/using-geoprocessing-options-to-control-tool-execution.htm" title="http://desktop.arcgis.com/en/arcmap/latest/analyze/executing-tools/using-geoprocessing-options-to-control-tool-execution.htm"&gt;Using geoprocessing options to control tool execution—Help | ArcGIS for Desktop&lt;/A&gt;&lt;/P&gt;&lt;P&gt;picture??&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Aug 2016 16:24:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/issue-with-script-in-model/m-p/869799#M2947</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-08-02T16:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with script in model</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/issue-with-script-in-model/m-p/869800#M2948</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Dan, I'll check.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Aug 2016 16:52:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/issue-with-script-in-model/m-p/869800#M2948</guid>
      <dc:creator>ChrisHolmes</dc:creator>
      <dc:date>2016-08-02T16:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with script in model</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/issue-with-script-in-model/m-p/869801#M2949</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No, they are not.&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/214269_pastedImage_0.png" style="max-height: 900px; max-width: 1200px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Aug 2016 17:14:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/issue-with-script-in-model/m-p/869801#M2949</guid>
      <dc:creator>ChrisHolmes</dc:creator>
      <dc:date>2016-08-02T17:14:39Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with script in model</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/issue-with-script-in-model/m-p/869802#M2950</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't have an answer for why this is not adding the layers to the Table of Contents as expected, but wanted to mention something that may trip things up in other regards.&amp;nbsp; The filename chosen for the rename has a dash in it and spaces, both of which can trip up ESRI GIS processes.&amp;nbsp; I'd avoid using the dash altogether and use underscores for any spaces.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;lyr.name = &lt;/EM&gt;&lt;SPAN class="string"&gt;&lt;EM&gt;"PROPOSED - site_polygon"&amp;nbsp; &lt;/EM&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chris Donohue, GISP&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Aug 2016 18:29:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/issue-with-script-in-model/m-p/869802#M2950</guid>
      <dc:creator>ChrisDonohue__GISP</dc:creator>
      <dc:date>2016-08-02T18:29:11Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with script in model</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/issue-with-script-in-model/m-p/869803#M2951</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good point. Thanks Chris. I had previously read that a while ago.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Aug 2016 19:10:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/issue-with-script-in-model/m-p/869803#M2951</guid>
      <dc:creator>ChrisHolmes</dc:creator>
      <dc:date>2016-08-02T19:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with script in model</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/issue-with-script-in-model/m-p/869804#M2952</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You may have to persist the layer by using&amp;nbsp; &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/copy-features.htm" title="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/copy-features.htm"&gt;Copy Features—Help | ArcGIS for Desktop&lt;/A&gt; or &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/save-to-layer-file.htm" title="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/save-to-layer-file.htm"&gt;Save To Layer File—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Aug 2016 20:36:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/issue-with-script-in-model/m-p/869804#M2952</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-08-02T20:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with script in model</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/issue-with-script-in-model/m-p/869805#M2953</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Dan. I’ll give this a try.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Aug 2016 21:09:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/issue-with-script-in-model/m-p/869805#M2953</guid>
      <dc:creator>ChrisHolmes</dc:creator>
      <dc:date>2016-08-02T21:09:30Z</dc:date>
    </item>
  </channel>
</rss>

