<?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 layers-arcpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/remove-layers-arcpy/m-p/192081#M14787</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Darren you understand me exactly. How can i solve this issue?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 30 Dec 2015 06:27:10 GMT</pubDate>
    <dc:creator>Yaron_YosefCohen</dc:creator>
    <dc:date>2015-12-30T06:27:10Z</dc:date>
    <item>
      <title>Remove layers-arcpy</title>
      <link>https://community.esri.com/t5/python-questions/remove-layers-arcpy/m-p/192078#M14784</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #222426; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; background-color: rgba(248, 248, 248, 0.6);"&gt;Expanding on my previous question &lt;A href="https://community.esri.com/message/495328" target="_blank"&gt;Remove Layers&lt;/A&gt; &lt;/SPAN&gt; ,&lt;/P&gt;&lt;P style="margin-bottom: 1em; font-size: 15px; color: #222426; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: rgba(248, 248, 248, 0.6);"&gt;i try to remove layers from mxd's (in ArcMap 10.3, Python 2.7.8), that don't appear in the data frame.&lt;/P&gt;&lt;P style="margin-bottom: 1em; font-size: 15px; color: #222426; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: rgba(248, 248, 248, 0.6);"&gt;The layers located in different disk drivers and in different folders and sub folders and each layer has different path orientation (right to left- different language from English). Only the MXD's located in "D:\desktop\Project" I using this code:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# -*- coding: cp1255 -*-
import arcpy,os
from arcpy import env

env.workspace = r"D:\desktop\Project"
for mxdname in arcpy.ListFiles('*.mxd'):
&amp;nbsp;&amp;nbsp;&amp;nbsp; print mxdname
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(os.path.join(env.workspace, mxdname))
&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd, "" ,df):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(lyr.getExtent())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print lyr.name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.getExtent() != None:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if df.extent.disjoint(lyr.getExtent()):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.RemoveLayer(df, lyr)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print u'Removed '+unicode(lyr) + ' lyr' 


&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()
del mxd&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For clarity, i asked it in &lt;A href="http://gis.stackexchange.com/questions/175008/remove-layers-in-sub-folders-using-python-path-orientation" title="http://gis.stackexchange.com/questions/175008/remove-layers-in-sub-folders-using-python-path-orientation" rel="nofollow noopener noreferrer" target="_blank"&gt;arcpy - Remove layers in sub folders using python- path orientation - Geographic Information Systems Stack Exchange&lt;/A&gt; &lt;A href="http://gis.stackexchange.com/questions/175008/remove-layers-in-sub-folders-using-python-path-orientation" title="http://gis.stackexchange.com/questions/175008/remove-layers-in-sub-folders-using-python-path-orientation" rel="nofollow noopener noreferrer" target="_blank"&gt;&lt;BR /&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:39:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-layers-arcpy/m-p/192078#M14784</guid>
      <dc:creator>Yaron_YosefCohen</dc:creator>
      <dc:date>2021-12-11T09:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: Remove layers-arcpy</title>
      <link>https://community.esri.com/t5/python-questions/remove-layers-arcpy/m-p/192079#M14785</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I suppose you know that even though no features overlap the data frame, the extent may overlap:&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/161898_pastedImage_0.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Dec 2015 18:50:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-layers-arcpy/m-p/192079#M14785</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-12-28T18:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: Remove layers-arcpy</title>
      <link>https://community.esri.com/t5/python-questions/remove-layers-arcpy/m-p/192080#M14786</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And I am assuming that you ruled out the obvious extent.overlaps?&amp;nbsp; &lt;A href="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-classes/extent.htm" title="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-classes/extent.htm"&gt;Extent—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Dec 2015 13:38:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-layers-arcpy/m-p/192080#M14786</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-12-29T13:38:40Z</dc:date>
    </item>
    <item>
      <title>Re: Remove layers-arcpy</title>
      <link>https://community.esri.com/t5/python-questions/remove-layers-arcpy/m-p/192081#M14787</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Darren you understand me exactly. How can i solve this issue?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Dec 2015 06:27:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-layers-arcpy/m-p/192081#M14787</guid>
      <dc:creator>Yaron_YosefCohen</dc:creator>
      <dc:date>2015-12-30T06:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: Remove layers-arcpy</title>
      <link>https://community.esri.com/t5/python-questions/remove-layers-arcpy/m-p/192082#M14788</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I know that fact, but my question is how can i remove layers that don't appear in the data frame, even though their layer extent cover up the data frame? is it possible?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Dec 2015 15:30:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-layers-arcpy/m-p/192082#M14788</guid>
      <dc:creator>Yaron_YosefCohen</dc:creator>
      <dc:date>2015-12-31T15:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: Remove layers-arcpy</title>
      <link>https://community.esri.com/t5/python-questions/remove-layers-arcpy/m-p/192083#M14789</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When i use&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp; extent.overlaps it remove land use layer- that ,in fact do exist in the layout, and finally i remain with river layer that don't exist in layout -but it extent coordination do cover the layout view:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt; &lt;IMG alt="1.jpg" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/167726_1.jpg" style="width: 620px; height: 416px;" /&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jan 2016 08:18:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-layers-arcpy/m-p/192083#M14789</guid>
      <dc:creator>Yaron_YosefCohen</dc:creator>
      <dc:date>2016-01-12T08:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: Remove layers-arcpy</title>
      <link>https://community.esri.com/t5/python-questions/remove-layers-arcpy/m-p/192084#M14790</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You now have a disconnect between your dataframe and its layout view, go back and zoom to the extent of the data (one of the layers) or to the full extent.&amp;nbsp; Does your image now appear back on the layout view?&amp;nbsp; If not, then you have your layout fixed and it doesn't change asyour data frame changes&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jan 2016 08:22:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-layers-arcpy/m-p/192084#M14790</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-01-12T08:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: Remove layers-arcpy</title>
      <link>https://community.esri.com/t5/python-questions/remove-layers-arcpy/m-p/192085#M14791</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Using the example provided by Darren, you could use a select by location (Intersect) using the extent from the dataframe. If the resulting layer does not contain any features, you can remove the layer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jan 2016 11:50:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-layers-arcpy/m-p/192085#M14791</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2016-01-12T11:50:19Z</dc:date>
    </item>
  </channel>
</rss>

