<?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: removeLayer() error in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/removelayer-error/m-p/1243569#M66340</link>
    <description>&lt;P&gt;Maybe you (or somebody else) has the project open in ArcGIS Pro?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 23 Dec 2022 13:44:11 GMT</pubDate>
    <dc:creator>DonMorrison1</dc:creator>
    <dc:date>2022-12-23T13:44:11Z</dc:date>
    <item>
      <title>removeLayer() error</title>
      <link>https://community.esri.com/t5/python-questions/removelayer-error/m-p/1243453#M66338</link>
      <description>&lt;P&gt;Hello-&lt;/P&gt;&lt;P&gt;I'm simply trying to remove a layer from an aprx using arcpy and am getting an error related to the save() function. Below is code and resulting error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# import modules
import arcpy
from arcpy import mp
import os

# remove temporary layers from the map
aprx = mp.ArcGISProject(r"N:\Projects\ElectionsOffice\VoterAddresses\VoterAddresses.aprx")
aprxMap = aprx.listMaps()[0]
for lyr in aprxMap.listLayers():
    if lyr.name == 'sgmj_2872_Layer2':
        aprxMap.removeLayer(lyr)
aprx.save()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;OSError&lt;/SPAN&gt;                                   Traceback (most recent call last)
In  &lt;SPAN class=""&gt;[40]&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;7&lt;/SPAN&gt;:     aprx.save()

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;save&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;308&lt;/SPAN&gt;:   &lt;SPAN class=""&gt;return&lt;/SPAN&gt; convertArcObjectToPythonObject(&lt;SPAN class=""&gt;self&lt;/SPAN&gt;._arc_object.save(*gp_fixargs((), &lt;SPAN class=""&gt;True&lt;/SPAN&gt;)))

&lt;SPAN class=""&gt;OSError&lt;/SPAN&gt;: N:\Projects\ElectionsOffice\VoterAddresses\VoterAddresses.aprx&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2022 21:30:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/removelayer-error/m-p/1243453#M66338</guid>
      <dc:creator>ZacharyStanley</dc:creator>
      <dc:date>2022-12-22T21:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: removeLayer() error</title>
      <link>https://community.esri.com/t5/python-questions/removelayer-error/m-p/1243464#M66339</link>
      <description>&lt;P&gt;related information&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-questions/removelayer-require-some-kind-of-refresh/td-p/1109820" target="_blank"&gt;Solved: removeLayer require some kind of refresh? - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I would throw in a print statement or two since I suspect you have no aprxMap or perhaps layers to process.&lt;/P&gt;&lt;P&gt;If all seems fine try a saveAs instead of save, using a different output name to ensure that the process can complete with some form of "save" option&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2022 22:10:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/removelayer-error/m-p/1243464#M66339</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-12-22T22:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: removeLayer() error</title>
      <link>https://community.esri.com/t5/python-questions/removelayer-error/m-p/1243569#M66340</link>
      <description>&lt;P&gt;Maybe you (or somebody else) has the project open in ArcGIS Pro?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2022 13:44:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/removelayer-error/m-p/1243569#M66340</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2022-12-23T13:44:11Z</dc:date>
    </item>
  </channel>
</rss>

