<?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: How to Delete Temporary Feature Layers Not Loaded in Visible in MXD in ModelBuilder Questions</title>
    <link>https://community.esri.com/t5/modelbuilder-questions/how-to-delete-temporary-feature-layers-not-loaded/m-p/880422#M790</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/16643" target="_blank"&gt;Neal Banerjee&lt;/A&gt;‌&lt;/P&gt;&lt;P&gt;You could probably cobble something together from the arcpy.walk example 2. and the 2nd from Delete_management.&amp;nbsp; Untested of course&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; os

workspace &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"c:/data"&lt;/SPAN&gt;
to_del &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

walk &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Walk&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;workspace&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; topdown&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; datatype&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"RasterDataset"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; dirpath&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; dirnames&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; filenames &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; walk&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; filename &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; filenames&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"_layer"&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; filename&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
            to_del&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;filename&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
out &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;";"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;n &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; n &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; to_del&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;  &lt;SPAN class="comment token"&gt;# ---- generate a semi-colon delimited list&lt;/SPAN&gt;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; workspace
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;management&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Delete&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;out&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;/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>Sun, 12 Dec 2021 11:06:45 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2021-12-12T11:06:45Z</dc:date>
    <item>
      <title>How to Delete Temporary Feature Layers Not Loaded in Visible in MXD</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/how-to-delete-temporary-feature-layers-not-loaded/m-p/880421#M789</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a series of models/scripts that create many temporary feature layers based on selection (using the MakeFeatureLayer tool),&amp;nbsp; Since they are within models and scripttools they are not automatically loaded/visualized in my MXD (which is what I want).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was wonder if there is a way to programatically access and delete all these temporary layer files.&amp;nbsp; I know I can use 'Delete' to see them and delete them individually, but Im curious if there is a way to access in ArcPy so I could loop through all layers that end in "_Layer" and delete (see below.&amp;nbsp; I tried deleting everything in the 'in_memory' but that didnt remove them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do not want to delete the underlying feature class, just the instance of the layer.&amp;nbsp; When I manually delete the temporary layer using the delete tool, it does what I want (just deleting layer instance but maintaining data)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be appreciated&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;&lt;P&gt;Neal&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/498103_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Jun 2020 13:16:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/how-to-delete-temporary-feature-layers-not-loaded/m-p/880421#M789</guid>
      <dc:creator>NealBanerjee</dc:creator>
      <dc:date>2020-06-27T13:16:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to Delete Temporary Feature Layers Not Loaded in Visible in MXD</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/how-to-delete-temporary-feature-layers-not-loaded/m-p/880422#M790</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/16643" target="_blank"&gt;Neal Banerjee&lt;/A&gt;‌&lt;/P&gt;&lt;P&gt;You could probably cobble something together from the arcpy.walk example 2. and the 2nd from Delete_management.&amp;nbsp; Untested of course&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; os

workspace &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"c:/data"&lt;/SPAN&gt;
to_del &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

walk &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Walk&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;workspace&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; topdown&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; datatype&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"RasterDataset"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; dirpath&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; dirnames&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; filenames &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; walk&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; filename &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; filenames&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"_layer"&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; filename&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
            to_del&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;filename&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
out &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;";"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;n &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; n &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; to_del&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;  &lt;SPAN class="comment token"&gt;# ---- generate a semi-colon delimited list&lt;/SPAN&gt;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; workspace
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;management&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Delete&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;out&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;/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>Sun, 12 Dec 2021 11:06:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/how-to-delete-temporary-feature-layers-not-loaded/m-p/880422#M790</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-12-12T11:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to Delete Temporary Feature Layers Not Loaded in Visible in MXD</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/how-to-delete-temporary-feature-layers-not-loaded/m-p/880423#M791</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Neal,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What you are doing is correct and what I would do, you run the delete tool and just give it the&amp;nbsp;&lt;EM&gt;Layer&lt;/EM&gt; name and that deletes the Layer that is in memory and not the source (Feature Class).&amp;nbsp; Deleting in_memory would only delete the Feature Class if your model had written to in_memory. Dan's code above is a "red herring", it is deleting the Feature Classes and not Layers created by the Make Feature Layer tool.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In model builder I would delete the layer as below, note the output of the selection (which in your case would undoubtedly have more tools attached to it) is a PRECONDITION, i.e. once all the processing is done delete the layer object.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/499885_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jul 2020 10:44:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/how-to-delete-temporary-feature-layers-not-loaded/m-p/880423#M791</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2020-07-10T10:44:49Z</dc:date>
    </item>
  </channel>
</rss>

