Select to view content in your preferred language

Using GET VALUE in an iterative model

2848
13
Jump to solution
08-03-2017 06:03 AM
MaraKaminowitz
Frequent Contributor

Hello.  I have a data processing model  in ModelBuilder that makes heavy use of the "Get field value" tool.  I need to iterate the model over many tables in a geodatabase.  When I do this, I do not get the correct values on the output based on the Get field - for each input table, the output is the same each time.  I think what is happening is the Get values are being held over from the first run of the model and not being picked up again with values from the next table as the model re-runs.  I have also had the same issue trying to use batch on the model.  Is there some command I can add to the end of the model that will clear the Get values from the system memory?  This is in Desktop 10.4.

0 Kudos
13 Replies
XanderBakker
Esri Esteemed Contributor

I'm glad the code is helpful and that you can adjust it to your needs. Would be nice to hear what calculations should be done differently. If you need some additional explanation on the code, I can provide a more detailed description. It is also possible to create a tool from it which can be used in model builder.

0 Kudos
MaraKaminowitz
Frequent Contributor

The field REG contains the regional mean to calculate the scores from. The same result could be obtained summing the tracts for the field of interest and calculating it against the summed total population - but again I don't think this would have been obvious without further explanation.  Taking the mean of the percentages creates an unstable result - the regional mean would vary depending on if you used tracts, counties, or other geography. Summing the geographies and taking the percent from the sum gives a consistent number for the region.  But this script is a great help and I will put it to good use.

XanderBakker
Esri Esteemed Contributor

Thanks for the explanation

0 Kudos
curtvprice
MVP Esteemed Contributor

I am not great with Python so if I can find an MB solution I'd like to.

I am big proponent of using the Calculate Value tool to run little snippets of Python for things like this to simplify your model and make it validate faster (and sometimes avoid depending on Model Builder's sometimes wonky validation, which I think was tripping you up). This approach takes advantage of Model Builder's ease of use, while you build your Python skills in the direction of Xander's, which I must admit I envy!!  

Here's a little example of what I'm talking about from your workflow. This little script could be enhanced to also initialize your field values as well using either Calculate Field or an update cursor.

# Calculate Value Expression
addfields(r"%Output Feature Class (7)%")
# Calculate Value Code Block
def addfields(ds):
  # add fields SCORE1 - SCORE8 
  for ff in range(1,9): 
    arcpy.AddField_management(ds, "SCORE{}".format(ff), "DOUBLE")
  return ds
# Calculate Value Data Type: Feature Class‍‍‍‍‍‍‍‍
# (Setting this allows you connect the Calculate Value result
# to a tool that needs Feature Class input)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I have also had the same issue trying to use batch on the model.

Batch is not supported with Model Builder tools. You should use iterators instead. 

 

Note, if you post code in the future check this out:

/blogs/dan_patterson/2016/08/14/script-formatting?sr=search&searchId=3ad791a4-288b-4f6c-aa72-f20f682...