1

How do you use python in a ArcGIS 10.3 script to list/print the shapefiles with a message from the result of a geoprocessing tool in the progress window/dialog box. For example;

abc.shp
1234.shp
zyx.shp
987.shp

The above 4 datasets have been projected to: WGS_1984_World_Mercator and saved in C:\GIS_Result

I have been looking at this example; http://resources.arcgis.com/en/help/main/10.2/index.html#//03q30000000q000000

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Apr 13, 2015 at 3:20
3
  • 1
    Welcome to GIS SE! Would you be able to edit your question to include details of the GIS software and version that you are using to try and do this, please? Also, can you include details of what you have tried so far. For example, if you are using ArcGIS for Desktop to write a Python script tool then I suspect your code should include arcpy.ListFeatureClasses(). Commented Apr 13, 2015 at 3:34
  • What sort of dialog box? Python does not natively have a dialog/message box interface, are you trying to print the names to be sure you're getting them all? Commented Apr 13, 2015 at 3:40
  • @MichaelMiles-Stimson I think the question is referring to the geoprocessing progress dialog that shows while an ArcGIS for Desktop tool is running in the foreground. Commented Apr 13, 2015 at 4:09

2 Answers 2

2

I'm going to assume that you are using ArcPy from ArcGIS for Desktop to write a Python script tool.

To send any messages to the geoprocessing progress dialog you can use

arcpy.AddMessage() 

For example:

arcpy.AddMessage("abc.shp")

or:

fc = "abc.shp"
arcpy.AddMessage(fc)
answered Apr 13, 2015 at 4:14
1
  • works for me, there's also AddWarning and AddError. If you want to go to the next level then you can use open("file name",'w') and write() functions to write to a log file. Like I said previously there's no forms installed by default, that doesn't mean there aren't any, pyWin and QT both provide good options (and I'm sure there's more) of throwing up a dialog/message box without too much effort. Commented Apr 13, 2015 at 4:41
0

The arcpy.AddMessage is bread and butter for adding your own messages in ArcToolbox Scripts tools. Also you can get the geoprocessing messages with arcpy.GetMessage/s. These are very powerful when used in: if else and try statements.

Adding A Script Tool

 import arcpy
 import os
 arcpy.AddMessage(" ")
 arcpy.AddMessage("===================================================================")
 arcpy.AddMessage(" ")
 arcpy.AddMessage(" Data Walk: Listings Rasters & Repair Standalone Feature Classes")
 arcpy.AddMessage(" ")
 FolderOrWorkspace = arcpy.GetParameterAsText(0)
 RasterCount = 0
 FeatureClassCount = 0
 DataList = []
 for dirname, dirnames, filenames in os.walk(FolderOrWorkspace):
 for subdirname in dirnames:
 arcpy.env.workspace = os.path.join(dirname, subdirname)
 RasterList = arcpy.ListRasters()
 for raster in RasterList:
 RasterCount = (RasterCount +1)
 arcpy.AddMessage(" - RASTER:" + str(RasterCount) +" Name: "+raster +" Within: "+subdirname)
 desc = arcpy.Describe(raster)
 SR = desc.spatialReference
 try:
 arcpy.AddMessage(" - Band Count: %d" % desc.bandCount)
 except:
 arcpy.AddMessage(" - Does Not Support Bands")
 try:
 arcpy.AddMessage(" - Compression Type: %s" % desc.compressionType)
 except:
 arcpy.AddMessage(" - Does Not Support Compression")
 try:
 arcpy.AddMessage(" - Raster Format: "+desc.format)
 except:
 arcpy.AddError(" - Raster Format: Error") #Error Message
 arcpy.AddMessage(" - Spatial Reference: "+SR.name)
 arcpy.AddMessage(" - Reference Type: "+SR.type)
 arcpy.AddMessage(" ")
 FeatureClassList = arcpy.ListFeatureClasses()
 for Feature in FeatureClassList:
 desc = arcpy.Describe(Feature)
 FeaturePath = os.path.join(desc.path,Feature)
 SR = desc.spatialReference
 FeatureClassCount = (FeatureClassCount +1)
 arcpy.AddMessage(" - FEATURE CLASS:" + str(FeatureClassCount) +" Name: "+Feature +" Within: "+subdirname)
 arcpy.AddMessage(" - Shape Type: "+desc.shapeType)
 arcpy.AddMessage(" - Spatial Reference: "+SR.name)
 arcpy.AddMessage(" - Reference Type: "+SR.type)
 try:
 arcpy.RepairGeometry_management(FeaturePath, "DELETE_NULL" )
 MesseageText = arcpy.GetMessages(1)
 if MesseageText =="":
 arcpy.AddMessage(" - Repair: geometry is good: " )
 else:
 arcpy.AddMessage(" - Repair: was poor: " )
 arcpy.AddMessage(" ")
 arcpy.AddMessage(str(MesseageText))
 arcpy.AddMessage(" ")
 except Exception as e:
 arcpy.AddError(e.message) # prints the error messages(ie the geometry is empty)
 arcpy.AddMessage(" ")
 arcpy.AddMessage("===================================================================")
 #arcpy.GetMessages(0) # prints all the messages
 #arcpy.GetMessages(1) # prints warning messages
 #arcpy.GetMessages(2) # prints error messages

Screen Grab of GetMessages

answered Apr 15, 2015 at 3:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.