<?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: Remove all layers except one in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/remove-all-layers-except-one/m-p/306798#M23840</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;it seems like you're trying to find an equality between two layer objects, i'd probably utilise the .name property for evaluation. you've also got a bad indent at the bottom. Might work, might not, I'm not a doctor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;aprx &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ArcGISProject&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"CURRENT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
mp &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; aprx&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;listMaps&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Map"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# Remove all layers except coast&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; rmlyr &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;listLayers&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; rmlyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;name &lt;SPAN class="operator token"&gt;!=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Coast"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;removeLayer&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;rmlyr&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 14:41:18 GMT</pubDate>
    <dc:creator>DavidPike</dc:creator>
    <dc:date>2021-12-11T14:41:18Z</dc:date>
    <item>
      <title>Remove all layers except one</title>
      <link>https://community.esri.com/t5/python-questions/remove-all-layers-except-one/m-p/306797#M23839</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I'm making the transition from ArcMap to ArcGIS Pro so please forgive my ignorance...&lt;/P&gt;&lt;P&gt;At the start of my Arcpy script, I am trying to delete all of my layers in my layout except 'Coast'. When I run my script below it crashes ArcGIS Pro. Any advice graciously accepted.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;aprx &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ArcGISProject&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"CURRENT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
mp &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; aprx&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;listMaps&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Map"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# Remove all layers except coast&lt;/SPAN&gt;
keeplyr &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;listLayers&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Coast"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; rmlyr &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;listLayers&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; rmlyr &lt;SPAN class="operator token"&gt;!=&lt;/SPAN&gt; keeplyr&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;removeLayer&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;rmlyr&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:41:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-all-layers-except-one/m-p/306797#M23839</guid>
      <dc:creator>DamianMilne</dc:creator>
      <dc:date>2021-12-11T14:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: Remove all layers except one</title>
      <link>https://community.esri.com/t5/python-questions/remove-all-layers-except-one/m-p/306798#M23840</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;it seems like you're trying to find an equality between two layer objects, i'd probably utilise the .name property for evaluation. you've also got a bad indent at the bottom. Might work, might not, I'm not a doctor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;aprx &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ArcGISProject&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"CURRENT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
mp &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; aprx&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;listMaps&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Map"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# Remove all layers except coast&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; rmlyr &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;listLayers&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; rmlyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;name &lt;SPAN class="operator token"&gt;!=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Coast"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;removeLayer&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;rmlyr&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:41:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-all-layers-except-one/m-p/306798#M23840</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-12-11T14:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: Remove all layers except one</title>
      <link>https://community.esri.com/t5/python-questions/remove-all-layers-except-one/m-p/306799#M23841</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you David, turns out the layers I was trying to remove were actually group layers (apologies for omitting that fairly significant detail), however your response did put me on the right track. For the benefit of other newbs like me here is my code snippit.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; rmlyr &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;listLayers&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; rmlyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;isGroupLayer&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
   mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;removeLayer&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;rmlyr&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:41:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-all-layers-except-one/m-p/306799#M23841</guid>
      <dc:creator>DamianMilne</dc:creator>
      <dc:date>2021-12-11T14:41:21Z</dc:date>
    </item>
  </channel>
</rss>

