Is there a way in Model Builder to display a calculated amount on the map?

2180
6
02-15-2019 04:48 AM
AliceAnderson
New Contributor

In Model Builder I create a layer that has values for each record, I want to calculate the % of records that are above a certain value and display that amount on the box with a message like "Areas covered: X%" where X is the calculated value. I've been looking around and have not seen anything on how to do this but there must be a way?

0 Kudos
6 Replies
TedKowal
Occasional Contributor III

I have never done it ... but this looks promising:

create a custom python script to run within model builder that will display a message box and send the into to the message box function to display.

ArcGIS Help (10.2, 10.2.1, and 10.2.2) 

0 Kudos
DuncanHornby
MVP Notable Contributor

I would say although you might be able to do what Ted Kowal has suggested, do you actually want to do that? Think about it no geoprocessing tool does what you are asking. It would essentially lock the model as it halts to display a dialog box. This would break the design philosophy of models in that they can be used and embedded within other models. If you had a model that was firing off an event to display in a dialog box that would just bring things to a grinding halt....

I think a far better and sensible approach is to turn your logic into a python tool as Ted says but write the final message to the standard message box which captures and displays all output of geoprocessing tools. If you tend to run tools in the background you won't see this and would need to go to the results pane to see the messages, or just turn off background processing.

In python to write a message to the results dialog box you would use arcpy.AddMessage("Hello World!"), explore the help file and look into how to turn a script into a script tool.

0 Kudos
TedKowal
Occasional Contributor III

I agree with Duncan Hornby ... just because you can does not mean it is the right thing to do.....  If I need to acquire user input or notifications that require action I generally use arcObject programming where I can control when geoprocessing starts or stops.

curtvprice
MVP Esteemed Contributor

You can execute some Python code using the Calculate Value tool to calculate a text string and locate (by name) and update a text element on the map layout. 

Introduction to arcpy.mapping—Help | ArcGIS Desktop 

TextElement—Help | ArcGIS Desktop 

Untested code:

# calculate value expression (uses Get Count results from model)
update("%GetCount Output%","%Total Records%")
# code block - text box in map is named CountMessage
def update(count, tot):
  mxd = arcpy.mapping.MapDocument("CURRENT")
  tbox = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "CountMessage")[0]
  pct = int(100 * float(count) / float(tot))
  tbox.text = "Area: {}%".format(pct)
  arcpy.RefreshActiveView()
  del mxd‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
ChelseaRozek
MVP Regular Contributor

That's cool, I didn't know you could do that! I'm making a simple model for non-GIS people to run, and now they can have a quick report to print!

FYI to anyone using the code, you need to change it to:

def update(count, tot😞

0 Kudos
curtvprice
MVP Esteemed Contributor

Thanks Chelsea Rozek‌ - fixed it!

0 Kudos