<?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: Stop layers used for analysis from being automatically added to map in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/stop-layers-used-for-analysis-from-being/m-p/328347#M25563</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;arcpy.env.addOutputsToMap = False&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;do the intermediate stuff here&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;just before you make the final output&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.addOutputsToMap = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and that final output appears on the map&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 26 Nov 2012 17:26:58 GMT</pubDate>
    <dc:creator>markdenil</dc:creator>
    <dc:date>2012-11-26T17:26:58Z</dc:date>
    <item>
      <title>Stop layers used for analysis from being automatically added to map</title>
      <link>https://community.esri.com/t5/python-questions/stop-layers-used-for-analysis-from-being/m-p/328346#M25562</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have written a python script that selects a subset of areas based on location, then adds the selected feature classes to a map. The copy of the map I save to a user specified output location is correct, however, I would like to have the map document that is open and running the script also be correct. Currently the full layers in which the selections are being performed on are automatically being added to the map as well as the final selected files. I've tried adding code to remove the full layers with no success. Any suggestions? (NOTE: This is a small portion of a much larger script)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy, os&amp;nbsp; def add2map (filename): &amp;nbsp;&amp;nbsp;&amp;nbsp; """adds a layer to an existing map document that is located in the tooldata folder""" &amp;nbsp;&amp;nbsp;&amp;nbsp; addLayer = arcpy.mapping.Layer(filename) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df,addLayer)&amp;nbsp; #Add Selected Feature Classes to Map arcpy.SetProgressorLabel("Creating Map") printMessage("Creating map of selected counties and CA's in "+arcpy.env.workspace+"...")&amp;nbsp; mapName = os.path.dirname(arcpy.env.workspace)+"/PCAmap.mxd" mxd = arcpy.mapping.MapDocument(mapName) ##mxd = arcpy.mapping.MapDocument("CURRENT")- tried this but it adds all layers to map not just the 2 I specify dfs = arcpy.mapping.ListDataFrames(mxd) df = dfs[0]&amp;nbsp; #Convert selected conservation areas and counties to layer file #NOTE: Can not use OutputFL and pcaFL because it will map the all features with selected areas highlighted.&amp;nbsp; selectedCounties = outName(OutputFC,"_Layer") selectedPCA = outName(pca_selected,"_Layer") arcpy.MakeFeatureLayer_management(OutputFC, selectedCounties) arcpy.MakeFeatureLayer_management(pca_selected,selectedPCA)&amp;nbsp; #Apply symbology&amp;nbsp; CountySymLayer = arcpy.env.workspace+"/Layers/WNC_Counties.lyr" PCAsymLayer = arcpy.env.workspace+"/Layers/PCA.lyr" arcpy.ApplySymbologyFromLayer_management(selectedPCA,PCAsymLayer) arcpy.ApplySymbologyFromLayer_management(selectedCounties,CountySymLayer)&amp;nbsp; arcpy.SetParameterAsText(1,OutputFL) arcpy.SetParameterAsText(2,pcaFL)&amp;nbsp; add2map(selectedCounties) add2map(selectedPCA)&amp;nbsp; #Save a COPY of the map &amp;amp; export to jpg format&amp;nbsp; mxd.saveACopy(outputWorkspace+os.sep+"PCA_COPY.mxd") printMessage("Map document of selected counties and selected PCA's saved to "+outputWorkspace) JPG = outputWorkspace+"/PCAmap_COPY.jpg"&amp;nbsp; arcpy.mapping.ExportToJPEG(mxd,JPG) printMessage("JPEG of map docment saved to "+outputWorkspace)&amp;nbsp; ##Remove Layers - tried removing the pre-analysis layers after mapping the selected layers but this doesn't work.&amp;nbsp; ##lyrs = arcpy.mapping.ListLayers(mxd,"",df) ##lyr1 = lyrs[2] ##lyr2 = lyrs[3] ##arcpy.mapping.RemoveLayer(df,lyr1) ##arcpy.mapping.RemoveLayer(df,lyr2)&amp;nbsp; arcpy.RefreshActiveView() arcpy.RefreshTOC() del mxd&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Nov 2012 16:25:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stop-layers-used-for-analysis-from-being/m-p/328346#M25562</guid>
      <dc:creator>RachelAlbritton1</dc:creator>
      <dc:date>2012-11-26T16:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: Stop layers used for analysis from being automatically added to map</title>
      <link>https://community.esri.com/t5/python-questions/stop-layers-used-for-analysis-from-being/m-p/328347#M25563</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;arcpy.env.addOutputsToMap = False&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;do the intermediate stuff here&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;just before you make the final output&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.addOutputsToMap = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and that final output appears on the map&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Nov 2012 17:26:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stop-layers-used-for-analysis-from-being/m-p/328347#M25563</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2012-11-26T17:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: Stop layers used for analysis from being automatically added to map</title>
      <link>https://community.esri.com/t5/python-questions/stop-layers-used-for-analysis-from-being/m-p/328348#M25564</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for the response, unfortunately its still adding the layers to the map.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I added the line of code before the first line of the code previously posted: arcpy.env.addOutputsToMap = False&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Map portion of script is here&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;then before adding the selected files to the map my code now looks like this&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

arcpy.env.addOutputsToMap = True
add2map(selectedCounties)
add2map(selectedPCA)

#Save a COPY of the map &amp;amp; export to jpg format
mxd.saveACopy(outputWorkspace+os.sep+"PCA_COPY.mxd")

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Even if I completely remove the line of code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.addOutputsToMap = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The full files that the selected files are being pulled from are still being added to the map.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:33:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stop-layers-used-for-analysis-from-being/m-p/328348#M25564</guid>
      <dc:creator>RachelAlbritton1</dc:creator>
      <dc:date>2021-12-11T15:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: Stop layers used for analysis from being automatically added to map</title>
      <link>https://community.esri.com/t5/python-questions/stop-layers-used-for-analysis-from-being/m-p/328349#M25565</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try changing it in the Geoprocessing Options. Maybe the application settings are overriding the script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is this happening &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;just&lt;/SPAN&gt;&lt;SPAN&gt; for layers you're running a selection on? Do you have multiple dataframes or just one?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sounds like this &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;might&lt;/SPAN&gt;&lt;SPAN&gt; be similar to something I had happen when using SelectLayerByAttribute_managment. Here's my post for that:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://forums.arcgis.com/threads/70974-Layer-getting-copied-erroneously" rel="nofollow" target="_blank"&gt;http://forums.arcgis.com/threads/70974-Layer-getting-copied-erroneously&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's what I had to do to get the open map to update:&lt;/SPAN&gt;&lt;BR /&gt;&lt;UL&gt;&lt;BR /&gt;&lt;LI&gt;Use "CURRENT" for the mxd&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Make sure I was on the "List by Drawing Order" tab in the TOC&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Make sure the script activated the dataframe the layer was in before running the selection (shouldn't be an issue if you only have one data frame)&lt;/LI&gt;&lt;BR /&gt;&lt;/UL&gt;&lt;SPAN&gt;If the layers you're running the selections on aren't in the map initially, it might be difficult to do. It seemed like if it didn't see a layer with the same TOC name in the active data frame, it would bring a copy into that dataframe. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I didn't think to try changing the Geoprocessing Options at the time. I ultimately only cared about my output pdf's being correct and didn't dig any deeper once I figured out they were coming out fine.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Nov 2012 18:38:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stop-layers-used-for-analysis-from-being/m-p/328349#M25565</guid>
      <dc:creator>MattSayler__Work_</dc:creator>
      <dc:date>2012-11-26T18:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: Stop layers used for analysis from being automatically added to map</title>
      <link>https://community.esri.com/t5/python-questions/stop-layers-used-for-analysis-from-being/m-p/328350#M25566</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Got it! I had to go to Geoprocessing Options and uncheck "Add results of geoprocessing results to display." A little odd since the layers that were appearing weren't the results, but it works.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Nov 2012 18:25:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stop-layers-used-for-analysis-from-being/m-p/328350#M25566</guid>
      <dc:creator>RachelAlbritton1</dc:creator>
      <dc:date>2012-11-27T18:25:12Z</dc:date>
    </item>
  </channel>
</rss>

