<?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 problem with arcpy.mapping.RemoveLayer in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/problem-with-arcpy-mapping-removelayer/m-p/592122#M46422</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to remove a layer from my map. this code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(str(arcpy.mapping.ListLayers (mxd, "", df)))
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(addstru)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.RemoveLayer (df, addstru)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(str(arcpy.mapping.ListLayers (mxd, "", df)))&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gets me this result:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[&amp;lt;map layer u'StruxPts_v04'&amp;gt;, &amp;lt;map layer u'Land_Projects_Parcels_P6'&amp;gt;]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;StruxPts_v04&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[&amp;lt;map layer u'StruxPts_v04'&amp;gt;, &amp;lt;map layer u'Land_Projects_Parcels_P6'&amp;gt;]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As you can see, the layer 'StruxPts_v04' was not removed. When does this sort of thing occur?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT: I'm thinking it has something to do with my searchcursor. addstru is searched, but I delete the cursor's variables prior to the code above.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 18 Jan 2014 21:25:30 GMT</pubDate>
    <dc:creator>Emilbrundage</dc:creator>
    <dc:date>2014-01-18T21:25:30Z</dc:date>
    <item>
      <title>problem with arcpy.mapping.RemoveLayer</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-arcpy-mapping-removelayer/m-p/592122#M46422</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to remove a layer from my map. this code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(str(arcpy.mapping.ListLayers (mxd, "", df)))
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(addstru)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.RemoveLayer (df, addstru)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(str(arcpy.mapping.ListLayers (mxd, "", df)))&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gets me this result:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[&amp;lt;map layer u'StruxPts_v04'&amp;gt;, &amp;lt;map layer u'Land_Projects_Parcels_P6'&amp;gt;]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;StruxPts_v04&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[&amp;lt;map layer u'StruxPts_v04'&amp;gt;, &amp;lt;map layer u'Land_Projects_Parcels_P6'&amp;gt;]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As you can see, the layer 'StruxPts_v04' was not removed. When does this sort of thing occur?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT: I'm thinking it has something to do with my searchcursor. addstru is searched, but I delete the cursor's variables prior to the code above.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 18 Jan 2014 21:25:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-arcpy-mapping-removelayer/m-p/592122#M46422</guid>
      <dc:creator>Emilbrundage</dc:creator>
      <dc:date>2014-01-18T21:25:30Z</dc:date>
    </item>
    <item>
      <title>Re: problem with arcpy.mapping.RemoveLayer</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-arcpy-mapping-removelayer/m-p/592123#M46423</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cursor shouldn't cause such behavior. I think there might be something with referencing layer you're trying to remove (addstru variable).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Can you try change code to:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
arcpy.AddMessage(str(arcpy.mapping.ListLayers (mxd, "", df)))
arcpy.AddMessage(addstru)
arcpy.mapping.RemoveLayer(df, arcpy.mapping.ListLayers(mxd, 'StruxPts_v04)[0])
arcpy.AddMessage(str(arcpy.mapping.ListLayers (mxd, "", df)))
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Arek&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:25:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-arcpy-mapping-removelayer/m-p/592123#M46423</guid>
      <dc:creator>ArkadiuszMatoszka</dc:creator>
      <dc:date>2021-12-12T01:25:53Z</dc:date>
    </item>
  </channel>
</rss>

