<?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: Write all Add Messages to text file in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/write-all-add-messages-to-text-file/m-p/1013400#M25001</link>
    <description>&lt;LI-CODE lang="python"&gt;msg = "start\n"
stuff
msg += "did something\n"
stuff
msg += "did more something\n"
stuff
msg += "done\n"
with open(r"c:\somefolder\Output.txt", "w") as text_file:
    text_file.write(msg)&lt;/LI-CODE&gt;&lt;P&gt;usually works&lt;/P&gt;</description>
    <pubDate>Sat, 02 Jan 2021 17:49:20 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2021-01-02T17:49:20Z</dc:date>
    <item>
      <title>Write all Add Messages to text file</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/write-all-add-messages-to-text-file/m-p/1013387#M24997</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a script tool that I use 'Add Message' to indicate progress during tool execution.&amp;nbsp; I would like to also write everything that I am writing to a text/log file.&amp;nbsp; I know I can do this manually by use a separate standard Python logfile.write process, but wanted to see if anyway to either capture messages at one time&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Neal&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jan 2021 14:49:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/write-all-add-messages-to-text-file/m-p/1013387#M24997</guid>
      <dc:creator>NealBanerjee</dc:creator>
      <dc:date>2021-01-02T14:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: Write all Add Messages to text file</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/write-all-add-messages-to-text-file/m-p/1013390#M24998</link>
      <description>&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/getmessages.htm" target="_blank"&gt;GetMessages—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;If it was wrapped up into a single tool execution I guess, otherwise it's a case of logging each add Message to a list.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jan 2021 15:15:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/write-all-add-messages-to-text-file/m-p/1013390#M24998</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-01-02T15:15:44Z</dc:date>
    </item>
    <item>
      <title>Re: Write all Add Messages to text file</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/write-all-add-messages-to-text-file/m-p/1013398#M24999</link>
      <description>&lt;P&gt;Thanks David, in my case it is a number of messages that want to capture.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jan 2021 17:01:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/write-all-add-messages-to-text-file/m-p/1013398#M24999</guid>
      <dc:creator>NealBanerjee</dc:creator>
      <dc:date>2021-01-02T17:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: Write all Add Messages to text file</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/write-all-add-messages-to-text-file/m-p/1013399#M25000</link>
      <description>&lt;P&gt;Can you wrap the script into a function, then grab all the messages in a single call after it's been executed ?(unsure myself - the method could be better elaborated on in the help).&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jan 2021 17:06:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/write-all-add-messages-to-text-file/m-p/1013399#M25000</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-01-02T17:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: Write all Add Messages to text file</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/write-all-add-messages-to-text-file/m-p/1013400#M25001</link>
      <description>&lt;LI-CODE lang="python"&gt;msg = "start\n"
stuff
msg += "did something\n"
stuff
msg += "did more something\n"
stuff
msg += "done\n"
with open(r"c:\somefolder\Output.txt", "w") as text_file:
    text_file.write(msg)&lt;/LI-CODE&gt;&lt;P&gt;usually works&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jan 2021 17:49:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/write-all-add-messages-to-text-file/m-p/1013400#M25001</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-01-02T17:49:20Z</dc:date>
    </item>
    <item>
      <title>Re: Write all Add Messages to text file</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/write-all-add-messages-to-text-file/m-p/1013415#M25002</link>
      <description>&lt;P&gt;Thank you Dan and David for your help. What I ended up doing is I think along the lines of what you both mentioned, but maybe a little different.&amp;nbsp; I first created a very simple mini-function in my main script that takes a string parameter.&amp;nbsp; The function then uses 'AddMessage' to return the message to user running script tool and the logfile.write to write same message to a separate text log file.&amp;nbsp; Below is function I created and a snippet of code showing how I used it.&amp;nbsp; Maybe not the most elaborate, but better than having to write each message basically twice.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def WriteMsg(strMsg):
    arcpy.AddMessage(strMsg)
    logfile.write(strMsg + "\n")
    return
### Simple snippet below

lstdomains = arcpy.da.ListDomains(inFGDB)          #Get list of domains in inFGDB
addmsg="Processing domains in input workspace: {0} and writing as tables in: {1}".format(inFGDB, outFGDB)
WriteMsg(addmsg)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jan 2021 20:42:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/write-all-add-messages-to-text-file/m-p/1013415#M25002</guid>
      <dc:creator>NealBanerjee</dc:creator>
      <dc:date>2021-01-02T20:42:31Z</dc:date>
    </item>
  </channel>
</rss>

