<?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: Unexpected script results when adding and removing layers in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588637#M93356</link>
    <description>&lt;P&gt;Updated snapshot.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Feb 2025 17:50:21 GMT</pubDate>
    <dc:creator>TaiDuong</dc:creator>
    <dc:date>2025-02-24T17:50:21Z</dc:date>
    <item>
      <title>Unexpected script results when adding and removing layers</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588598#M93348</link>
      <description>&lt;P&gt;Trying the following:&lt;/P&gt;&lt;P&gt;1. Add polygon Layer from gpkg and rename Layer&lt;/P&gt;&lt;P&gt;2. Add Line Layer from gpkg and rename Layer&lt;/P&gt;&lt;P&gt;3. Run Model with Parameters set to added Layers&lt;/P&gt;&lt;P&gt;4. Remove Layers.&lt;/P&gt;&lt;P&gt;Then repeat for the next geocell (many many more)&lt;/P&gt;&lt;P&gt;Problem.&lt;/P&gt;&lt;P&gt;All outputs are the same as the first Layers added. Even though the Layers are removed and new Layers added and I clean out the ScratchGDB&amp;nbsp; all outputs are the same as the first one. If I don't remove the Layers and just keep adding new Layers it works ok. BUT I have hundreds of geopackages and the project gets bloated and ARCGIs runs very very slowly (10x slower) so I really need to remove Layers after each time the Model is run.&lt;/P&gt;&lt;P&gt;Help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;from WorldFPatbx.DeleteScratchGDB import DeleteScratchGDB&lt;BR /&gt;from WorldFPatbx.ModelSub01 import ModelSub01&lt;BR /&gt;aprx = arcpy.mp.ArcGISProject('CURRENT')&lt;BR /&gt;current_map = aprx.activeMap&lt;BR /&gt;def ModelMaster_9_3_45__135():&lt;BR /&gt;arcpy.AddMessage("Starting Building_9_3_45__135")&lt;BR /&gt;current_map.addDataFromPath("D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_3\\World_9_3_45_-135.gpkg\\main.multipolygons")&lt;BR /&gt;layer = current_map.listLayers("main.multipolygons")[0]&lt;BR /&gt;layer.name = "multipolygons_45__135"&lt;BR /&gt;polyLyr=layer&lt;BR /&gt;current_map.addDataFromPath("D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_3\\World_9_3_45_-135.gpkg\\main.lines")&lt;BR /&gt;layer = current_map.listLayers("main.lines")[0]&lt;BR /&gt;layer.name = "lines_45__135"&lt;BR /&gt;lineLyr=layer&lt;BR /&gt;main_multipolygons = "multipolygons_45__135"&lt;BR /&gt;main_lines = "lines_45__135"&lt;BR /&gt;Footprints_gpkg = "D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_3\\BuildingFP\\Footprints_9_3_45__135.gpkg"&lt;BR /&gt;Buildings = "D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_3\\BuildingFP\\Footprints_9_3_45__135.gpkg\\Buildings"&lt;BR /&gt;ModelSub01(Input_Lines=main_lines, Input_polygons=main_multipolygons, FPGeopackage=Footprints_gpkg, GPFootprints=Buildings)&lt;BR /&gt;DeleteScratchGDB()&lt;BR /&gt;current_map.removeLayer(polyLyr)&lt;BR /&gt;current_map.removeLayer(lineLyr)&lt;BR /&gt;arcpy.AddMessage("Building_9_3_45__135 Finished")&lt;BR /&gt;with arcpy.EnvManager(scratchWorkspace="C:\\ArcGISProjectNXT\\WorldFP\\WorldFP.gdb", workspace="C:\\ArcGISProjectNXT\\WorldFP\\WorldFP.gdb"):&lt;BR /&gt;ModelMaster_9_3_45__135()&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;def ModelMaster_9_3_45__134():&lt;BR /&gt;arcpy.AddMessage("Starting Building_9_3_45__134")&lt;BR /&gt;current_map.addDataFromPath("D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_3\\World_9_3_45_-134.gpkg\\main.multipolygons")&lt;BR /&gt;layer = current_map.listLayers("main.multipolygons")[0]&lt;BR /&gt;layer.name = "multipolygons_45__134"&lt;BR /&gt;polyLyr=layer&lt;BR /&gt;current_map.addDataFromPath("D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_3\\World_9_3_45_-134.gpkg\\main.lines")&lt;BR /&gt;layer = current_map.listLayers("main.lines")[0]&lt;BR /&gt;layer.name = "lines_45__134"&lt;BR /&gt;lineLyr=layer&lt;BR /&gt;main_multipolygons = "multipolygons_45__134"&lt;BR /&gt;main_lines = "lines_45__134"&lt;BR /&gt;Footprints_gpkg = "D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_3\\BuildingFP\\Footprints_9_3_45__134.gpkg"&lt;BR /&gt;Buildings = "D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_3\\BuildingFP\\Footprints_9_3_45__134.gpkg\\Buildings"&lt;BR /&gt;ModelSub01(Input_Lines=main_lines, Input_polygons=main_multipolygons, FPGeopackage=Footprints_gpkg, GPFootprints=Buildings)&lt;BR /&gt;DeleteScratchGDB()&lt;BR /&gt;current_map.removeLayer(polyLyr)&lt;BR /&gt;current_map.removeLayer(lineLyr)&lt;BR /&gt;arcpy.AddMessage("Building_9_3_45__134 Finished")&lt;BR /&gt;with arcpy.EnvManager(scratchWorkspace="C:\\ArcGISProjectNXT\\WorldFP\\WorldFP.gdb", workspace="C:\\ArcGISProjectNXT\\WorldFP\\WorldFP.gdb"):&lt;BR /&gt;ModelMaster_9_3_45__134()&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 16:34:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588598#M93348</guid>
      <dc:creator>TaiDuong</dc:creator>
      <dc:date>2025-02-24T16:34:31Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected script results when adding and removing layers</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588604#M93351</link>
      <description>&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633" target="_blank"&gt;Code formatting ... the Community Version - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;line numbers will be useful to those wanting to examine your code&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 16:48:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588604#M93351</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2025-02-24T16:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected script results when adding and removing layers</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588609#M93352</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TaiDuong_0-1740419350970.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/126128i03D2DD84769F6B0A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TaiDuong_0-1740419350970.png" alt="TaiDuong_0-1740419350970.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 17:49:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588609#M93352</guid>
      <dc:creator>TaiDuong</dc:creator>
      <dc:date>2025-02-24T17:49:27Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected script results when adding and removing layers</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588632#M93355</link>
      <description>&lt;P&gt;Now just apply that to the code you posted in the original thread&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 17:44:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588632#M93355</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2025-02-24T17:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected script results when adding and removing layers</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588637#M93356</link>
      <description>&lt;P&gt;Updated snapshot.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 17:50:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588637#M93356</guid>
      <dc:creator>TaiDuong</dc:creator>
      <dc:date>2025-02-24T17:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected script results when adding and removing layers</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588682#M93359</link>
      <description>&lt;P&gt;Som progress. but&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code in your first thread&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;from WorldFPatbx.DeleteScratchGDB import DeleteScratchGDB&lt;BR /&gt;from WorldFPatbx.ModelSub01 import ModelSub01&lt;BR /&gt;aprx = arcpy.mp.ArcGISProject('CURRENT')&lt;/P&gt;&lt;P&gt;.... snip ....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code after following the thread I posted and using code blocks&amp;nbsp; (&amp;nbsp; &amp;lt;/&amp;gt; )&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
from WorldFPatbx.DeleteScratchGDB import DeleteScratchGDB
from WorldFPatbx.ModelSub01 import ModelSub01
aprx = arcpy.mp.ArcGISProject('CURRENT')
.....snip....&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 19:16:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588682#M93359</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2025-02-24T19:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected script results when adding and removing layers</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588716#M93362</link>
      <description>&lt;P&gt;Not sure what y'all are trying to tell me here Dan. But here's yet another snapshot. Anyway , ignoring the fact I'm not a real developer and write sloppy code, if anyone has any idea why it's not working as desired I sure would appreciate it.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TaiDuong_0-1740428873974.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/126153iB714709B7FA71A04/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TaiDuong_0-1740428873974.png" alt="TaiDuong_0-1740428873974.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 20:28:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588716#M93362</guid>
      <dc:creator>TaiDuong</dc:creator>
      <dc:date>2025-02-24T20:28:00Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected script results when adding and removing layers</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588722#M93363</link>
      <description>&lt;P&gt;You are posting screen shots&lt;/P&gt;&lt;P&gt;hit ...&lt;/P&gt;&lt;P&gt;then &amp;lt;/&amp;gt;&lt;/P&gt;&lt;P&gt;pick your language&lt;/P&gt;&lt;P&gt;paste your code in there&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;People can copy and paste code from an image, but they can from a code block in a post or response&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 20:43:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588722#M93363</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2025-02-24T20:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected script results when adding and removing layers</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588724#M93364</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 20:47:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588724#M93364</guid>
      <dc:creator>TaiDuong</dc:creator>
      <dc:date>2025-02-24T20:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected script results when adding and removing layers</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588726#M93365</link>
      <description>&lt;P&gt;Thanks.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
from MyProjectTwoatbx.DeleteScratchGDB import DeleteScratchGDB
from MyProjectTwoatbx.ModelSub01 import ModelSub01
aprx = arcpy.mp.ArcGISProject('CURRENT')
current_map = aprx.activeMap
def ModelMaster_9_1_45__165():
    arcpy.AddMessage("Starting Building_9_1_45__165")
    current_map.addDataFromPath("D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_1\\World_9_1_45_-165.gpkg\\main.multipolygons")
    layer = current_map.listLayers("main.multipolygons")[0]
    layer.name = "multipolygons_45__165"
    polyLyr=layer
    current_map.addDataFromPath("D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_1\\World_9_1_45_-165.gpkg\\main.lines")
    layer = current_map.listLayers("main.lines")[0]
    layer.name = "lines_45__165"
    lineLyr=layer
    arcpy.env.overwriteOutput = True
    main_multipolygons = "multipolygons_45__165"
    main_lines = "lines_45__165"
    Footprints_gpkg = "D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_1\\BuildingFP\\Footprints_9_1_45__165.gpkg"
    Buildings = "D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_1\\BuildingFP\\Footprints_9_1_45__165.gpkg\\Buildings"
    ModelSub01(Input_Lines=main_lines, Input_polygons=main_multipolygons, FPGeopackage=Footprints_gpkg, GPFootprints=Buildings) 
    DeleteScratchGDB()
    current_map.removeLayer(polyLyr)
    current_map.removeLayer(lineLyr)
    arcpy.AddMessage("Building_9_1_45__165 Finished")
with arcpy.EnvManager(scratchWorkspace="C:\\ArcGISProjectNXT\\MyProjectTwo\\MyProjectTwo.gdb", workspace="C:\\ArcGISProjectNXT\\MyProjectTwo\\MyProjectTwo.gdb"):
    ModelMaster_9_1_45__165()


def ModelMaster_9_1_45__164():
    arcpy.AddMessage("Starting Building_9_1_45__164")
    current_map.addDataFromPath("D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_1\\World_9_1_45_-164.gpkg\\main.multipolygons")
    layer = current_map.listLayers("main.multipolygons")[0]
    layer.name = "multipolygons_45__164"
    polyLyr=layer
    current_map.addDataFromPath("D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_1\\World_9_1_45_-164.gpkg\\main.lines")
    layer = current_map.listLayers("main.lines")[0]
    layer.name = "lines_45__164"
    lineLyr=layer
    arcpy.env.overwriteOutput = True
    main_multipolygons = "multipolygons_45__164"
    main_lines = "lines_45__164"
    Footprints_gpkg = "D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_1\\BuildingFP\\Footprints_9_1_45__164.gpkg"
    Buildings = "D:\\ESRI-Daylight\\NCERTS_1.0\\World_9_1\\BuildingFP\\Footprints_9_1_45__164.gpkg\\Buildings"
    ModelSub01(Input_Lines=main_lines, Input_polygons=main_multipolygons, FPGeopackage=Footprints_gpkg, GPFootprints=Buildings) 
    DeleteScratchGDB()
    current_map.removeLayer(polyLyr)
    current_map.removeLayer(lineLyr)
    arcpy.AddMessage("Building_9_1_45__164 Finished")
with arcpy.EnvManager(scratchWorkspace="C:\\ArcGISProjectNXT\\MyProjectTwo\\MyProjectTwo.gdb", workspace="C:\\ArcGISProjectNXT\\MyProjectTwo\\MyProjectTwo.gdb"):
    ModelMaster_9_1_45__164()&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 24 Feb 2025 20:50:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/unexpected-script-results-when-adding-and-removing/m-p/1588726#M93365</guid>
      <dc:creator>TaiDuong</dc:creator>
      <dc:date>2025-02-24T20:50:12Z</dc:date>
    </item>
  </channel>
</rss>

