HOW TO
Instructions provided describe how to write the results of geoprocessing tools to a text file.
When a geoprocessing tool is run, the results are written to the Geoprocessing Results Window in ArcMap or ArcCatalog; they are also written to a history log file. There are times when it is helpful to have the geoprocessing results written to a text file.
The following Python script sample runs the Buffer tool and then writes the geoprocessing results to a text file. The script can be run through the Python window in ArcMap. Refer to ArcMap: Using the Python window for more information.
Code Sample for ArcGIS 10.x:
import arcpy # Input feature classes to buffer inFC = "C:\\Temp\\Georgia.shp" # Output Feature Class outFC = "C:\\Temp\\Georgia_Buffer.shp" # Buffer distance dist = "50 miles" # Run buffer tool arcpy.Buffer_analysis(inFC, outFC, dist) # Write messages to a Text File txtFile = open("c:\\temp\\GPMessages.txt","w") txtFile.write (arcpy.GetMessages()) txtFile.close()
Code Sample for ArcGIS 9.2/9.3.x:
import arcgisscripting gp = arcgisscripting.create() gp.Toolbox = "Analysis" # Input feature classes to buffer inFC = "C:\\Temp\\Georgia.shp" # Output Feature Class outFC = "C:\\Temp\\Georgia_Buffer.shp" # Buffer distance dist = "50 miles" # Run buffer tool gp.buffer(inFC, outFC, dist) # Write messages to a Text File txtFile = open("c:\\temp\\GPMessages.txt","w") txtFile.write (gp.GetMessages()) txtFile.close()
Get help from ArcGIS experts
Download the Esri Support App