<?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: Why doesn't Python script add output automatically to map? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602150#M47083</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Instead of adding it in the main script, it works by adding it to the start of the validation script. In my case, a plot that I created with Matplotlib was being added to the TOC in the current ArcMap session. This prevented it from happening. If it isn't adding automatically, just switch the boolean to True.&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;class&lt;/SPAN&gt; &lt;SPAN class="token class-name"&gt;ToolValidator&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;object&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&lt;SPAN class="string token"&gt;"""Class for validating a tool's parameter values and controlling
the behavior of the tool's dialog."""&lt;/SPAN&gt;

arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;addOutputsToMap &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;False&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;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 01:49:29 GMT</pubDate>
    <dc:creator>MatthewHowe</dc:creator>
    <dc:date>2021-12-12T01:49:29Z</dc:date>
    <item>
      <title>Why doesn't Python script add output automatically to map?</title>
      <link>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602138#M47071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is the first Python script I've written in a few years, so this is probably a rookie question.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I wrote this script that creates 3 different buffers around a point shapefile, and it works, but doesn't automatically add the buffers to the map, it just saves them in the specified workspace. In my Geoprocessinng options I have it set to add outputs to map and it works with all ESRI tools but not my script. Any ideas? Thanks in advance!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my script:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Script Name: EpicenterBuffers
# Description: Creates 10, 50, and 100 KM
#&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; buffers around an epicenter
# Created By:&amp;nbsp; Kirstyn Pittman
# Date:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11/24/14


import arcpy
arcpy.env.workspace = r"H:\Drafting Department\Python\EpicenterBuffers"
shp = "Location"
distanceList = ["10 kilometers","50 kilometers","100 kilometers"]
# Loop through each distance in the distanceList
for dist in distanceList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; outName = shp+"_"+dist
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Buffer_analysis(shp, outName, dist)
print "Finished Buffering"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:49:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602138#M47071</guid>
      <dc:creator>KirstynAlex</dc:creator>
      <dc:date>2021-12-12T01:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't Python script add output automatically to map?</title>
      <link>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602139#M47072</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.addOutputsToMap = true&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/#/env/018z0000004s000000/" title="http://resources.arcgis.com/en/help/main/10.2/#/env/018z0000004s000000/"&gt;env(arcpy)&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Nov 2014 17:45:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602139#M47072</guid>
      <dc:creator>TimothyHales</dc:creator>
      <dc:date>2014-11-24T17:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't Python script add output automatically to map?</title>
      <link>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602140#M47073</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks! I tried that, gives me this error though:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Executing: EpicenterBuffer C:\GISData\10345_01_VineyardPointe\LOCATION.shp&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Start Time: Mon Nov 24 09:56:05 2014&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Running script EpicenterBuffer...&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;lt;type 'exceptions.NameError'&amp;gt;: name 'true' is not defined&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Failed to execute (EpicenterBuffer).&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Failed at Mon Nov 24 09:56:06 2014 (Elapsed Time: 1.00 seconds)&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Nov 2014 17:54:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602140#M47073</guid>
      <dc:creator>KirstynAlex</dc:creator>
      <dc:date>2014-11-24T17:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't Python script add output automatically to map?</title>
      <link>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602141#M47074</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;P&gt;It accepts a Boolean value, so that should have been capitalized. &lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;0/1 or True/False&lt;/P&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Nov 2014 17:56:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602141#M47074</guid>
      <dc:creator>TimothyHales</dc:creator>
      <dc:date>2014-11-24T17:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't Python script add output automatically to map?</title>
      <link>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602142#M47075</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Oh I see! Well I didn't get an error that time and the tool still worked like it did before--still doesn't add the outputs to ArcMap but adds them to my workspace. Not sure what the problem is!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Nov 2014 18:14:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602142#M47075</guid>
      <dc:creator>KirstynAlex</dc:creator>
      <dc:date>2014-11-24T18:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't Python script add output automatically to map?</title>
      <link>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602143#M47076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A standalone python script is not a geoprocessing tool, and the import of arcpy does not replicate all of the behaviors that operate within an open session of ArcMap.&amp;nbsp; Environment settings that apply directly to an open session of ArcMap are ignored by Python scripts, such as arcpy.overwriteOutputs = True and &lt;SPAN style="color: #000000; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;arcpy.addOutputsToMap = True; but they are exposed through arcpy to control the user experience in an open session of ArcMap (i.e., whatever arcpy did to these settings will persist and affect how ArcMap responds when the user tries to save over a file or run a geoprocessing tool, so a programmer can control user capabilities).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;You need to explicitly do these tasks with arcpy.&amp;nbsp; You have to use the &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//00s300000025000000"&gt;arcpy.mapping.AddLayer&lt;/A&gt; method to have your script add layers after creating new data.&amp;nbsp; You also cannot overwrite data, and have to test if it exists and then delete it with &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//018v0000004p000000"&gt;arcpy.Exists()&lt;/A&gt; and arcpy.Delete_management() (the Exist sample code demonstrates this).&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Nov 2014 18:36:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602143#M47076</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-11-24T18:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't Python script add output automatically to map?</title>
      <link>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602144#M47077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, I understand!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Nov 2014 18:51:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602144#M47077</guid>
      <dc:creator>KirstynAlex</dc:creator>
      <dc:date>2014-11-24T18:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't Python script add output automatically to map?</title>
      <link>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602145#M47078</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you set up the python script as a script tool with parameters for your output feature classes they will be added to your map - when the script is run as a script tool from ArcMap. If you are generating the pathnames inside the script, the output parameters would be set up as derived parmeters and you would return their values using the arcpy SetParameterAsText method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is all covered in the help on script tools.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Nov 2014 04:37:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602145#M47078</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-11-25T04:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't Python script add output automatically to map?</title>
      <link>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602146#M47079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Wait - are you saying that if I set arcpy.overwriteOutput = True in a stand alone script run from an IDE (PyScripter, in my case) it has no effect? Or maybe I'm misunderstanding. That's not my takeaway from the &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/Script_environments/001w00000037000000/"&gt;help files&lt;/A&gt;, &lt;EM&gt;'Environment values set within scripts only apply to the execution of the script'.&lt;/EM&gt;‌ Am I missing something?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Nov 2014 13:01:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602146#M47079</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2014-11-25T13:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't Python script add output automatically to map?</title>
      <link>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602147#M47080</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, I am saying that based on years of having that environment parameter ignored.&amp;nbsp; I left it in my scripts, but always get errors that I am trying to overwrite existing files if that is the only parameter used to overwrite files in my script.&amp;nbsp; It was only the Exist() method and Delete_management() methods that have allowed me to use Scheduler or Idle for my scripts.&amp;nbsp; I don't think that option works at all outside of the Python window inside a live session of ArcMap or perhaps a tool run within an open ArcMap session.&amp;nbsp; Python has no innate interactions with ArcMap, and importing arcpy does not set your script up with full a Desktop like environment without interacting with an actual ArcMap session.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Nov 2014 14:09:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602147#M47080</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-11-25T14:09:39Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't Python script add output automatically to map?</title>
      <link>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602148#M47081</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just tested it to make sure nothing has changed.&amp;nbsp; A script run in Idle with the env.overwriteOutputs = True setting produces errors like this when attempting to overwrite an output with a tool.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\Python26\ArcGIS10.0\temp_sums.py", line 26, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Statistics_analysis(intable, outtable, stats)&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\analysis.py", line 1089, in Statistics&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise e&lt;/P&gt;&lt;P&gt;ExecuteError: Failed to execute. Parameters are not valid.&lt;/P&gt;&lt;P&gt;ERROR 000725: Output Table: Dataset \\agency\agencydfs\CustomApps\rfairhur\Layers\Application.gdb\PARCELS_ASSESSOR_SUMS already exists.&lt;/P&gt;&lt;P&gt;Failed to execute (Statistics).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the quote is true that env settings have no effect outside the script, then I have to consider this behavior a bug, since overwriteOutputs has never worked inside my scripts run from Idle.&amp;nbsp; However, this bug has existed since the old GP syntax and has never been addressed since python geoprocessing scripts were developed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Based on Curtis' post it does seem that the overwrite outputs works as a tool.&amp;nbsp; However, most of my scripts are for after hours batch processing, so it does not help me in that case.&amp;nbsp; The Exists() and Delete_management() approach will work in any set up, so I recommend using it to avoid a gotcha if you want to do stand alone scripts.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Nov 2014 15:11:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602148#M47081</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-11-25T15:11:45Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't Python script add output automatically to map?</title>
      <link>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602149#M47082</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hmm... not getting an error in a script I just wrote, but maybe it's not overwriting either? Will have to check this out. Good to know.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Nov 2014 15:48:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602149#M47082</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2014-11-25T15:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't Python script add output automatically to map?</title>
      <link>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602150#M47083</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Instead of adding it in the main script, it works by adding it to the start of the validation script. In my case, a plot that I created with Matplotlib was being added to the TOC in the current ArcMap session. This prevented it from happening. If it isn't adding automatically, just switch the boolean to True.&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;class&lt;/SPAN&gt; &lt;SPAN class="token class-name"&gt;ToolValidator&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;object&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&lt;SPAN class="string token"&gt;"""Class for validating a tool's parameter values and controlling
the behavior of the tool's dialog."""&lt;/SPAN&gt;

arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;addOutputsToMap &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;False&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;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:49:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-doesn-t-python-script-add-output-automatically/m-p/602150#M47083</guid>
      <dc:creator>MatthewHowe</dc:creator>
      <dc:date>2021-12-12T01:49:29Z</dc:date>
    </item>
  </channel>
</rss>

