Select to view content in your preferred language

Iterating both inputs for a tool in Modelbuilder

2129
8
Jump to solution
02-06-2019 04:06 PM
RebeccaFuda
Occasional Contributor

I have 2 folders, one with 3 shapefiles and one with 11.  I want to find the intersection for all possible combinations of the shapefiles in each folder, for a total of 33 resulting intersection shapefiles.  I have tried creating 2 sub-models that iterate through the folders, and used the output of each submodel as the inputs for the Intersect tool.  However, the model results in only one intersection shapefile.  How do I get the intersect tool to use all combinations of the shapefiles?

Test_sub2 submodel                                                                                    Test_sub1 submodel

0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor

Sorry Rebecca, been busy teaching, hopefully this will help you or someone else.

Here's the help on nesting models

Integrating a model within a model—Help | ArcGIS Desktop 

Here's an example model that does nested loops:

Nested Model 01

Nested Model 02

Executing (For): IterateCount 1 3 1

Start Time: Thu Feb 21 01:28:34 2019

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

Executing (Inside Model): InsideModel 1

Start Time: Thu Feb 21 01:28:34 2019

Executing (For): IterateCount 1 3 1

Start Time: Thu Feb 21 01:28:34 2019

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

Executing (Calculate Value Print Values): CalculateValue ""Outside: " + "1" + "  Inside: " + "1"" # Variant

Start Time: Thu Feb 21 01:28:34 2019

Value = Outside: 1  Inside: 1

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

Executing (For): IterateCount 1 3 1

Start Time: Thu Feb 21 01:28:34 2019

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

Executing (Calculate Value Print Values): CalculateValue ""Outside: " + "1" + "  Inside: " + "2"" # Variant

Start Time: Thu Feb 21 01:28:34 2019

Value = Outside: 1  Inside: 2

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

<<snip>>

Executing (For): IterateCount 1 3 1

Start Time: Thu Feb 21 01:28:34 2019

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

Executing (Calculate Value Print Values): CalculateValue ""Outside: " + "3" + "  Inside: " + "2"" # Variant

Start Time: Thu Feb 21 01:28:34 2019

Value = Outside: 3  Inside: 2

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

Executing (For): IterateCount 1 3 1

Start Time: Thu Feb 21 01:28:34 2019

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

Executing (Calculate Value Print Values): CalculateValue ""Outside: " + "3" + "  Inside: " + "3"" # Variant

Start Time: Thu Feb 21 01:28:34 2019

Value = Outside: 3  Inside: 3

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

Executing (For): IterateCount 1 3 1

Start Time: Thu Feb 21 01:28:34 2019

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.02 seconds)

Executing (For): IterateCount 1 3 1

Start Time: Thu Feb 21 01:28:34 2019

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

View solution in original post

8 Replies
DarrenWiens2
MVP Honored Contributor

Does the Intersect tool only run once or 33 times?

0 Kudos
RebeccaFuda
Occasional Contributor

I need it to run 33 times, but it is only running once.

0 Kudos
curtvprice
MVP Esteemed Contributor

I believe the intersect process must be nested the furthest in, not in the main model ... 

iterate folder1  (calls)

   iterate folder2, run intersect

You could probably put the intersect process inside the "iterate folder2" model.

RebeccaFuda
Occasional Contributor

I'm not sure I am completely understanding you, but if I do that the model runs only 11 times (iterates through only 1 folder), not 33 times.

0 Kudos
curtvprice
MVP Esteemed Contributor

Sorry Rebecca, been busy teaching, hopefully this will help you or someone else.

Here's the help on nesting models

Integrating a model within a model—Help | ArcGIS Desktop 

Here's an example model that does nested loops:

Nested Model 01

Nested Model 02

Executing (For): IterateCount 1 3 1

Start Time: Thu Feb 21 01:28:34 2019

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

Executing (Inside Model): InsideModel 1

Start Time: Thu Feb 21 01:28:34 2019

Executing (For): IterateCount 1 3 1

Start Time: Thu Feb 21 01:28:34 2019

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

Executing (Calculate Value Print Values): CalculateValue ""Outside: " + "1" + "  Inside: " + "1"" # Variant

Start Time: Thu Feb 21 01:28:34 2019

Value = Outside: 1  Inside: 1

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

Executing (For): IterateCount 1 3 1

Start Time: Thu Feb 21 01:28:34 2019

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

Executing (Calculate Value Print Values): CalculateValue ""Outside: " + "1" + "  Inside: " + "2"" # Variant

Start Time: Thu Feb 21 01:28:34 2019

Value = Outside: 1  Inside: 2

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

<<snip>>

Executing (For): IterateCount 1 3 1

Start Time: Thu Feb 21 01:28:34 2019

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

Executing (Calculate Value Print Values): CalculateValue ""Outside: " + "3" + "  Inside: " + "2"" # Variant

Start Time: Thu Feb 21 01:28:34 2019

Value = Outside: 3  Inside: 2

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

Executing (For): IterateCount 1 3 1

Start Time: Thu Feb 21 01:28:34 2019

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

Executing (Calculate Value Print Values): CalculateValue ""Outside: " + "3" + "  Inside: " + "3"" # Variant

Start Time: Thu Feb 21 01:28:34 2019

Value = Outside: 3  Inside: 3

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

Executing (For): IterateCount 1 3 1

Start Time: Thu Feb 21 01:28:34 2019

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.02 seconds)

Executing (For): IterateCount 1 3 1

Start Time: Thu Feb 21 01:28:34 2019

Succeeded at Thu Feb 21 01:28:34 2019 (Elapsed Time: 0.00 seconds)

RebeccaFuda
Occasional Contributor

Hi Curtis,


Can you clarify how you would extent my example above using Iterate Feature Classes and the intersect tool? I'm not clear on exactly how to set it up as the inputs for Iterate Feature Classes differ from the "For" interator...

0 Kudos
RebeccaFuda
Occasional Contributor

I believe I have discovered my issue.  I have tried using "Collect Values" after the iterator, but the output of "Collect values" does not work as an input for the Intersect tool.  This is documented as Bug NIM052331.  Any ideas for a workaround?

0 Kudos
curtvprice
MVP Esteemed Contributor

The bug says it was fixed before 10.0 was released, so I not convinced this is it.

Are you piping Collect Values directly into Intersect? This is not correct as the entire model iterates and you only want to run the Intersect once. Collect values should have its output marked as a parameter (in an "sub-model" that has the iterator) and the output piped to the Intersect tool in the external model that calls the sub-model.

0 Kudos