<?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: MakeFeatureLayer_management does not add layer to TOC? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/makefeaturelayer-management-does-not-add-layer-to/m-p/177464#M13648</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for replying Rebecca! The problem I have with the code sample is that it copies the data selection to disk. I was hoping to avoid this because I only need the data temporarily. If I run MakeFeatureLayer in the Python window, it adds a layer in my TOC without actually copying the data anywhere. I am curious as to why it does not do this when I run the same script as a tool. The help says: "...will not persist after the session ends unless... the map document is saved." Maybe I need to add some code to save my MXD before the tool finishes processing?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 01 Feb 2016 22:46:06 GMT</pubDate>
    <dc:creator>AustinRobey1</dc:creator>
    <dc:date>2016-02-01T22:46:06Z</dc:date>
    <item>
      <title>MakeFeatureLayer_management does not add layer to TOC?</title>
      <link>https://community.esri.com/t5/python-questions/makefeaturelayer-management-does-not-add-layer-to/m-p/177462#M13646</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have written a python script that utilizes arcpy.MakeFeatureLayer_management to create a layer from a selection set. If I run this script in the Python window in ArcMap it works -- it updates the Table of Contents with a temporary layer (i.e. referencing existing data rather than copying new data to disk). However, if I execute this script as a tool (script saved to a toolbox and run as geoprocessing) it runs but does not update the Table of Contents with a new layer. It is the exact same script (see below), just run in different ways. Can someone help me understand why the tool is not adding the layer, but the Python window does? Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy 
arcpy.env.overwiteOutput = True
#Specify the MXD project (CURRENT), dataframe (Layers), MapPage (004-21)
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
pagenm = "004-21"
#Defintion query expressions
apndq = "APN LIKE '" + pagenm + "%'"
#Apply defintion query to specified layer group
for lyr in arcpy.mapping.ListLayers(mxd, "AssessorsParcels"):
 if lyr.supports("DEFINITIONQUERY"):
&amp;nbsp; lyr.definitionQuery = str(apndq)
#Create MapPage Boundary Selection
arcpy.SelectLayerByLocation_management(r"Cadastral Data\Boundary","HAVE_THEIR_CENTER_IN",r"Cadastral Data\AssessorsParcels","","NEW_SELECTION")
#Create layer from selection and update symbology
arcpy.MakeFeatureLayer_management(r"Cadastral Data\Boundary", "BoundarySelection")
arcpy.ApplySymbologyFromLayer_management("BoundarySelection","H:\\Data\\Layers\\Boundary.lyr")

#Refresh the Active View
arcpy.RefreshTOC()
arcpy.RefreshActiveView()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
del mxd, df, pagenm&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:07:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/makefeaturelayer-management-does-not-add-layer-to/m-p/177462#M13646</guid>
      <dc:creator>AustinRobey1</dc:creator>
      <dc:date>2021-12-11T09:07:12Z</dc:date>
    </item>
    <item>
      <title>Re: MakeFeatureLayer_management does not add layer to TOC?</title>
      <link>https://community.esri.com/t5/python-questions/makefeaturelayer-management-does-not-add-layer-to/m-p/177463#M13647</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;From the help &lt;A href="http://desktop.arcgis.com/en/desktop/latest/tools/data-management-toolbox/make-feature-layer.htm#C_GUID-E7E83378-0AC6-48CE-A6F4-ACDF372AB3FF" title="http://desktop.arcgis.com/en/desktop/latest/tools/data-management-toolbox/make-feature-layer.htm#C_GUID-E7E83378-0AC6-48CE-A6F4-ACDF372AB3FF"&gt;Make Feature Layer—Help | ArcGIS for Desktop&lt;/A&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Creates a &lt;SPAN class="glossary"&gt;feature layer&lt;/SPAN&gt; from an input &lt;SPAN class="glossary"&gt;feature class&lt;/SPAN&gt; or &lt;SPAN class="glossary"&gt;layer&lt;/SPAN&gt; file. The layer that is created by the tool is temporary and will not persist after the session ends unless the layer is saved to disk or the map document is saved.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I was just needing the same thing and had to refresh my memory.&amp;nbsp; Take a look at the second code sample on the help page.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT:....but I'm not getting it to work right now either....just fyi.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Feb 2016 22:34:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/makefeaturelayer-management-does-not-add-layer-to/m-p/177463#M13647</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2016-02-01T22:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: MakeFeatureLayer_management does not add layer to TOC?</title>
      <link>https://community.esri.com/t5/python-questions/makefeaturelayer-management-does-not-add-layer-to/m-p/177464#M13648</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for replying Rebecca! The problem I have with the code sample is that it copies the data selection to disk. I was hoping to avoid this because I only need the data temporarily. If I run MakeFeatureLayer in the Python window, it adds a layer in my TOC without actually copying the data anywhere. I am curious as to why it does not do this when I run the same script as a tool. The help says: "...will not persist after the session ends unless... the map document is saved." Maybe I need to add some code to save my MXD before the tool finishes processing?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Feb 2016 22:46:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/makefeaturelayer-management-does-not-add-layer-to/m-p/177464#M13648</guid>
      <dc:creator>AustinRobey1</dc:creator>
      <dc:date>2016-02-01T22:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: MakeFeatureLayer_management does not add layer to TOC?</title>
      <link>https://community.esri.com/t5/python-questions/makefeaturelayer-management-does-not-add-layer-to/m-p/177465#M13649</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I remember how I was doing it in other scripts.&amp;nbsp; I tested to make sure I was in ArcMap (in case I'm running in ArcCatalog instead)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; #my variables pElevClass, unionOut and outDissolved are set to full paths of the output
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT")
except RuntimeError:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Not using ArcMap")
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; layerList = [pElevClass, unionOut, outDissolved] 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for layer in layerList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; addLayer = arcpy.mapping.Layer(layer)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists(addLayer):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, addLayer, "TOP")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("-&amp;gt; Added {0} to map.".format(layer)) #, finalLayer))&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.env.overwriteOutput = True&lt;/PRE&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Set so I can use the names multiple times...and actually have a section that I run thru an delete all my temp files so I don't end up with so many temps that I have to clean up later.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I had this working in another script last week.&amp;nbsp; With the temp files I wanted to add to the TOC, it sometimes added the layer to the TOC EACH time I ran it, but since they always pointed to the same file, even the previous versions in the TOC reflected the new data (as it should).&amp;nbsp; My guess is this paragraph doesn't make much sense....but maybe the code above will make it more clear.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:07:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/makefeaturelayer-management-does-not-add-layer-to/m-p/177465#M13649</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2021-12-11T09:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: MakeFeatureLayer_management does not add layer to TOC?</title>
      <link>https://community.esri.com/t5/python-questions/makefeaturelayer-management-does-not-add-layer-to/m-p/177466#M13650</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What are your script properties in terms of running the script in process and always running in the foreground?&amp;nbsp; Also, do you have Background Processing enabled in ArcGIS Desktop?&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Feb 2016 23:43:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/makefeaturelayer-management-does-not-add-layer-to/m-p/177466#M13650</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2016-02-01T23:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: MakeFeatureLayer_management does not add layer to TOC?</title>
      <link>https://community.esri.com/t5/python-questions/makefeaturelayer-management-does-not-add-layer-to/m-p/177467#M13651</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have it set to always run in foreground and run script in process. Background Processing is disabled. On the Geoprocessing Options window, under the Display/Temporary Data section, I have Add results of geoprocessing to the display enabled, and Results are temporary by default disabled.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Feb 2016 23:58:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/makefeaturelayer-management-does-not-add-layer-to/m-p/177467#M13651</guid>
      <dc:creator>AustinRobey1</dc:creator>
      <dc:date>2016-02-01T23:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: MakeFeatureLayer_management does not add layer to TOC?</title>
      <link>https://community.esri.com/t5/python-questions/makefeaturelayer-management-does-not-add-layer-to/m-p/177468#M13652</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This thread might be helpful&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/message/416673"&gt;Re: Get Attribute Value from Selected Feature&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Explains a bit about MakeFeatureLayer&amp;nbsp; and includes the "arcpy.mapping.AddLayer(df, addLayer, &lt;SPAN class="string"&gt;"TOP")" similar to my code above, but in a more straightforward manner.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Feb 2016 00:07:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/makefeaturelayer-management-does-not-add-layer-to/m-p/177468#M13652</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2016-02-02T00:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: MakeFeatureLayer_management does not add layer to TOC?</title>
      <link>https://community.esri.com/t5/python-questions/makefeaturelayer-management-does-not-add-layer-to/m-p/177469#M13653</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes! I was able to fix the problem using the below code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Create layer from selection
&lt;SPAN style="font-family: Consolas;"&gt;arcpy.SelectLayerByLocation_management("Target_Layer","HAVE_THEIR_CENTER_IN","Source_Layer","","NEW_SELECTION")&lt;/SPAN&gt;
arcpy.MakeFeatureLayer_management("Target_Layer", "Selection_LayerName")
selection = arcpy.mapping.Layer("Selection_LayerName")
arcpy.mapping.AddLayer(df, selection, "TOP")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is still a bit odd to me that the tool requires lines 04 &amp;amp; 05 yet the Python window did not. Alas, it works now, so I am satisfied. Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:07:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/makefeaturelayer-management-does-not-add-layer-to/m-p/177469#M13653</guid>
      <dc:creator>AustinRobey1</dc:creator>
      <dc:date>2021-12-11T09:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: MakeFeatureLayer_management does not add layer to TOC?</title>
      <link>https://community.esri.com/t5/python-questions/makefeaturelayer-management-does-not-add-layer-to/m-p/177470#M13654</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Glad you got it to work (I have mine working too).&amp;nbsp; Make sure to close this thread out by marking any answers that were helpful, and one as the correct. answer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Feb 2016 01:05:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/makefeaturelayer-management-does-not-add-layer-to/m-p/177470#M13654</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2016-02-02T01:05:39Z</dc:date>
    </item>
  </channel>
</rss>

