I have a script that accepts the input of four tables and then geocodes these tables. My goal is to display the name of the output feature class and the number of unmatched records for each iteration of geocoding. This information is displayed while the tool is running but to better the user experience I would like this info displayed after the script is finished.
Solved! Go to Solution.
So I figured out a few things that I was getting wrong but in the end, this is the simple code block:
arcpy.MakeFeatureLayer_management(geocode_result1, "geocode_result_1", whereClause)
result = arcpy.GetCount_management("geocode_result_1")
count = int(result[0])
if count > 0:
arcpy.AddMessage("Weekly Crime - Unmatched: " + str(count))
else:
arcpy.AddMessage("Weekly Crime: All Matched")
This will allow the end-user to quickly see if they need to rematch any unmatched records.
AddMessage—ArcPy Functions | Documentation
But you will only see the messages when you use "View Details" on the tool after it runs. Messages don't display in a popup or anything like that
Hey Dan I understand that the AddMessage function will work, but I don't know the correct syntax to receive the results from arcpy.GeocodeAddresses_geocoding to get the information I'm looking for to display under "View Details". For each file being geocoded I would like the name of the ouput feature class and the number of unmatched records to be shown.
You might want to consider adding the message at the completion of geocoding: make a feature layer of your geocoded results, select where status = 'U' and use get count to see how many are unmatched; return that count in your message.
Joe thank you for your suggestion. This is the code block that I came up with. Unfortunately, when I place it multiple times in the script to handle the number of inputs I get undesired results. I could probably set up a loop that runs through this code block, but my python skills are limited.
whereClause = "Status = 'U'"
arcpy.MakeFeatureLayer_management(geocode_result1, "geocode_result1", whereClause)
result = arcpy.GetCount_management("geocode_result1")
count = int(result.getOutput(0))
if count > 0:
try:
arcpy.AddMessage("Weekly Crime: Unmatched:" + count)
except:
arcpy.AddMessage("Weekly Crime: All Matched")
Below is the common result I receive. The two issues are for one, not all the messages are displayed. The second issue is that the outputs are wrong, "Weekly Crime 4 Weeks" should return the unmatched response not an all matched response.
Messages:
Running script Geocoding Weekly Crimes...
Weekly Crime 4 Weeks: All Matched
Weekly Crime 4 Weeks Night: All Matched
Completed script Geocoding Weekly Crimes...
line 4 is suspect:
count = int(result.getOutput(0))
count = int(result[0]))
My line 3 just worked for me....
So I figured out a few things that I was getting wrong but in the end, this is the simple code block:
arcpy.MakeFeatureLayer_management(geocode_result1, "geocode_result_1", whereClause)
result = arcpy.GetCount_management("geocode_result_1")
count = int(result[0])
if count > 0:
arcpy.AddMessage("Weekly Crime - Unmatched: " + str(count))
else:
arcpy.AddMessage("Weekly Crime: All Matched")
This will allow the end-user to quickly see if they need to rematch any unmatched records.
Here's a cooler way to format your message in line 5:
arcpy.Addmessage(f'Weekly Crime - Unmatched {count}')
see: https://realpython.com/python-f-strings/