Select to view content in your preferred language

ModelBuilder Inline Variable substitution failing for newly created geodatabase

889
2
Jump to solution
09-25-2023 10:13 PM
AditiPanhalkar
New Contributor II

Hi all, 

I'm trying to setup a model that pulls all feature layers from a hosted webservice (present in a Map) and selects and exports features from each feature layer that satisfies an SQL query to a new geodatabase.

The way I've set up my model is- A variable called ParkName prompts user to enter the name they want for the new geodatabase. An Iterate layers tool looks at all the feature layers within the webservice and each output layer is passed to Make Feature layer (with the required SQL) and Copy Features- to create feature layers with only the required features in a new geodatabase. I'm using inline variable substitution to give each layer the same name as their hosted counterpart. What I can't do is use inline variable substitution to have all these feature layers exported to the new geodatabase created earlier. It works perfectly when it's set to Default.gdb but not when it's set to %ExportGDB% 

I have also tried setting the new gdb as a precondition and as the current/scratch workspace, and tried using the tool export feature class to geodatabase but nothing seems to work. I am fairly new to ModelBuilder, hopefully I've explained the problem well enough. 

Any advise will be greatly appreciated. Thanks! 

1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor

I see a basic flaw in your model. Golden rule is EVERYTHING runs as many times as the iterator loops. EVERYTHING means stuff feeding into the iterator and unconnected parts of your model with or without preconditions.  So knowing that fact, what do you think your create file geodatabase tool is doing? It's creating the database X number of times...

The solution is to embed models within models. Have a master model with your create file geodatabase tool acting as a precondition to a sub-model. The sub-model containing the iterator and connecting logic. You then run the master model. Create geodatabase runs ONCE then logic feeds into sub-model with it's iterator.

Refer to help file on topic of embedding models. You'll need to take this approach if you also want loops within loops.

View solution in original post

0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor

I see a basic flaw in your model. Golden rule is EVERYTHING runs as many times as the iterator loops. EVERYTHING means stuff feeding into the iterator and unconnected parts of your model with or without preconditions.  So knowing that fact, what do you think your create file geodatabase tool is doing? It's creating the database X number of times...

The solution is to embed models within models. Have a master model with your create file geodatabase tool acting as a precondition to a sub-model. The sub-model containing the iterator and connecting logic. You then run the master model. Create geodatabase runs ONCE then logic feeds into sub-model with it's iterator.

Refer to help file on topic of embedding models. You'll need to take this approach if you also want loops within loops.

0 Kudos
AditiPanhalkar
New Contributor II

Hi Duncan, creating a submodel for the iteration worked perfectly, thanks, much appreciated! 

Cheers,

Aditi. 

0 Kudos