Modelbuilder/python solution to bypass geoprocessing functions with empty parameters

1157
5
02-01-2012 09:38 AM
SheaMeyer
New Contributor II
All help here is very much appreciated.

I am wondering if a model or python script can skip or bypass certain specified geoprocessing functions if the models parameters are empty.

I have a model that calculates a numerical output for a single polygon where the user must input 3 parameters. There has been a desire for a single model to combine that final calculation of many polygons.

My first thought was simple, I would just copy and paste the processes within the model for each possible polygon and set the parameters so the user would input the 3 for each possible polygon.

The issue is that although the user wants to have an option to calculate this value for every polygon (and combine them after the processing), there will be cases in which some of the polygons do not need analysis, and unfortunately leaving a default "0" will crash the model immediately.

So therefore, I was wondering if I continued on my initial path, is it possible that by leaving a parameter empty, can it bypass its functions all together?

Thank you very much for your time and assistance.
Tags (2)
0 Kudos
5 Replies
BruceNielsen
Occasional Contributor III
The way you would approach this in Python is to set up an if-then-else condition for the input parameter:
if gp.getparameterastext(0) = "": #I'm using 9.x syntax
    #Do whatever is necesssary if the parameter is absent
else:
    #Do whatever is necessary if the parameter is present

If you're running this from ArcToolbox, be sure you set the parameter as optional, so the tool won't demand a value before it will run.
0 Kudos
SheaMeyer
New Contributor II
Thank you for your response Bruce,

I was wondering however if an alternative is possible.

Is there any type of parameter I can set in the very beginning of a model that will skip the entire thing.

For instance, can I make a true or false domain that if the user selects false, none of the following functions will run?
0 Kudos
DarrenWiens2
MVP Honored Contributor
Check out the example on this page called "Setting a Boolean Variable as a Precondition".
0 Kudos
SheaMeyer
New Contributor II
An even easier method to my solution would be:

Can I make a precondition to the initial tool (starting the model) that the input parameter effecting it is not equal to 0?

*NOTE* These individual models will all be combined into one large model so it would be ideal that the models with a 0 as their input parameter would be overlooked entriely, where the others >0 would execute.
0 Kudos
SheaMeyer
New Contributor II
Check out the example on this page called "Setting a Boolean Variable as a Precondition".


That is EXACTLY what I needed! (FOR NOW I HOPE) HUGE THANK YOU!
0 Kudos