Conditional Custom Tool Parameter For Input Layer

740
4
10-06-2017 11:51 AM
PatrickMcKinney1
Occasional Contributor III

I'm developing a custom ArcGIS Desktop tool for my Planning department.  I want to provide users with an option for which dataset will be used as an input.  I want them to be able to select between 1) a layer (shapefile or featureclass) or 2) one ore more tax parcel ids that will be used to construct a feature layer using select by attribute.

Essentially, they will be choosing the layer from which to clip soils.  They will either be clipping soils against our tax parcels layer or a special feature class representing a farm.

I'd like the tool to only allow for one of these inputs based upon a true/false box parameter.  What is the best way to wire this up when creating the custom tool?

Thanks,

Patrick

0 Kudos
4 Replies
MitchHolley1
MVP Regular Contributor

Layers can be accepted in a tool if the Data Type is set to "Feature Layer".  Secondly, if you want to limit the input layer to some specific IDs, I would suggest using a SQL Expression parameter with the Data Type set to "SQL Expression".  This can be set to 'Optional' and you can set "Obtained from" to your input feature layer.  Just remember to incorporate this in the actual Python code. 

PatrickMcKinney1
Occasional Contributor III

Thanks! But that is not the issue I'm having. I want there to be a checkbox that essentially says "Input Farm is from Parcels". If that box is selected, then the user enters in parcel ID numbers.  The input dataset for the analysis is then the parcels (which is hard-coded in the script).

 If that box is not checked, then they input the location of a feature class representing the farm, which is  completely different feature class.

I essentially want input parameters to be conditional based upon a boolean box.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

Patrick, you could have:

"Input Farm by parcel'     as an 'optional' parameter, of integer type

and.....

"or Input Farm location"   also as an 'optional' of whatever type you need.

then you just need to check the logic to see which one has a value and which one doesn't and what to do the user inputs neither or both (my preference is to simply output a message and terminate)

In basic toolboxes, they don't offer the ability that I think you want since they lack 'event' listening parameters.  Ideally,you want a combobox (listbox with 2 choices) rather than a checkbox.  You would then have another parameter that allows 'any value' in it.  In the combobox, they would select one of two options showing, and enter the 'value' into the second line.  Your script would then determine what to do with the 'value' depending on the option chosen.  Hard to describe without actually creating one.  Maybe python toolboxes offer greater flexibility.

And finally... since tools are cheap and can reuse scripts, my preference is to have a toolbox with two tools... one for 

"input Farm by parcel'  and the second "input Farm location"   ... very clever ehh then the user has to decide what to do from the very beginning what they want to do.  The scripts process is controlled by the tool they are running it from.

RebeccaStrauch__GISP
MVP Esteemed Contributor

Patrick, I'm not sure if you have moved on or not, but I think what you want is using the validation

Customizing script tool behavior—Help | ArcGIS for Desktop 

In the past, I know I have been able to enable/disable and/or populate another parameter field based on another, but I struggle with getting the validation to work sometimes, although the sample makes it look rather easy

to enable or disable a parameter.