Select to view content in your preferred language

Is there a way to create a model that behaves like a toggle?

863
6
09-13-2019 06:31 AM
RPGIS
by
Frequent Contributor

Hi,

So I am working on a model where for every database, there is a feature class that gets selected, the count is taken for that feature class, and that populates a field in a table. This model runs for every row in a designated table. But what I am trying to accomplish is :

  1. for each record in table
    1. run model to get the feature class in the database, get the count for that feature class, and calculate the count in the table.
      1. When this model runs once, run the model for the next record in the table
  2. this process repeats for every table record and every database.
0 Kudos
6 Replies
curtvprice
MVP Esteemed Contributor

It sounds like you want to nest iterators one for iterating tables, and iteration for reach row in each table. This is done by creating a submodel that iterates by row on one table, then adding that model to another model that iterates by table. There are examples in the help:

ArcMap: Integrating a model within a model—Help | ArcGIS Desktop 

ArcGIS Pro: Add a submodel to a model—ArcGIS Pro | ArcGIS Desktop 

0 Kudos
RPGIS
by
Frequent Contributor

Thanks Curtis for the links. I have nested models within models before, but the issue I am facing currently is that I have multiple feature classes with these databases that I need to get counts for(which a simple select data and get count models could take care of). The issue I come across every time the model that I currently have runs, it will run through either one iteration process or the other fully, and not returning with the end result that I am looking to achieve. I am not sure if it is the way that the model is nesting or if it is the order in which it is nested.

So here are the cases for each instance where I am having issues:

  1. Iterate selected rows --> iterate multivalue(nested) --> select data (some feature class)(nested) --> Get Count(nested) --> Calculate Field(nested)
  2. Iterate multivalue --> iterate selected rows(nested) --> select data(some feature class)(nested) -->Get count(nested) -->Calculate Field(nested)

I have tried both and I am not sure if it is due to the way they are nested, or the order in which they run. I will keep trying, but perhaps it might be due to how they are nested which is causing one to run fully and.then the other. I will keep trying to see and testing each design.

The other option I am looking at is creating a script tool, which will be cleaner and more flexible. The databases in which this model is working with are personal databases, which arcpy doesn't recognize as well as it does file geodatabases. I figured out that despite this limitation, creating a script tool to run in process using modelbuilder seems to work with personal geodatabses. Any help on this too I would greatly appreciate.

Thanks,

Robert

0 Kudos
curtvprice
MVP Esteemed Contributor

I think you are on the right track to do this with a script, when looping gets really complicated python scripting is much easier to work with and more robust.

ArcMap background processing (64 bit) and ArcGIS Pro will not recognize them. Note, that if you have the ArcMap x64 geoprocessing installed and you run the python script from the command line, the x64 arcpy is the one you get. 

Background Geoprocessing (64-bit)—Help | ArcGIS Desktop 

0 Kudos
RPGIS
by
Frequent Contributor

Thanks Curtis,

I didn't know there was a difference depending on how the script is run. It's good to know that depending on where I plan on running the script.

0 Kudos
curtvprice
MVP Esteemed Contributor

If you are running a script from a command line, .bat or .ps1 you can specify the python to run 32-bit (so you can access .mdb for example) like this:

C:\Python27\ArcGIS10.6\python.exe myscript.py

0 Kudos
RPGIS
by
Frequent Contributor

Thanks again Curtis for the help. I do recall using something similar when I was taught how to use windows task scheduler to automate the scripts executions, but never thought to use command line for that. I never tried specifying how python should run, whether as 32 or 64 bit, but it is good to know that you can actually specify how it should run.

0 Kudos