model builder and user input

2832
4
01-16-2014 08:30 AM
jaykapalczynski
Frequent Contributor
I have a model that is working fine...the user is asked to select a county but out of the box its using the Query Builder.
I want to change this and have a form popup with a drop down box with the County names...then use that selection as the input variable to some other function later in the model like a clip or something.
Can this be done?  Any examples or documentation?
Thanks
0 Kudos
4 Replies
jaykapalczynski
Frequent Contributor
Right now I have a SELECTION in my Model...
I have a FC that is being selected and an Expression that is prompting the user for an input (query builder pops up)
Instead of the Query Builder and the Expression I simply want a form to popup with a drop down to allow the user to select and then have it build the query itself...then pass this to the SELECTION as the existing Expression is doing....hope that makes sense

Can I script a form or popup in model builder asking for user input?  Examples?  Documentation?

Thanks
0 Kudos
MattSayler
Occasional Contributor II
If you want to dynamically populate a picklist, that can be done by modifying the tool validation script (script tool properties, validation tab).

Basic example of generating a list of unique values for a picklist:
class ToolValidator:
 """Class for validating a tool's parameter values and controlling
 the behavior of the tool's dialog."""
 def __init__(self):
  """Setup the Geoprocessor and the list of tool parameters."""
  self.params = arcpy.GetParameterInfo()
  
 def initializeParameters(self):
  """Refine the properties of a tool's parameters.  This method is
  called when the tool is opened."""
  return
 def updateParameters(self):
  """Modify the values and properties of parameters before internal
  validation is performed.  This method is called whenever a parameter
  has been changed."""
  
                FC = r"C:\Path\To\FeatureClass"
                Col = "FieldName"
                self.params[0].filter.list = [str(val) for val in sorted(set(row.getValue(Col) for row in arcpy.SearchCursor(FC, None, None, Col)))]   #use a da cursor if @ 10.1+ 
  return
 def updateMessages(self):
  """Modify the messages created by internal validation for each tool
  parameter.  This method is called after internal validation."""
  return 
0 Kudos
jaykapalczynski
Frequent Contributor
Not really following that....can you explain a bit further...little green here.
I created a string variable and pointed that to the expression...although it will take multiple entries 'test1', 'test2'
it is not a drop down box....

In the expression I add this to point to the variable I String created...can I create a variable that is a drop down box with a list of values of which I can select more than one?

County_Nam in (%Name Of County Being Used For Search%)
0 Kudos
MattSayler
Occasional Contributor II
On second examination, I'm not sure the solution I provided would work for what you need. I was talking about making it so a tool's dialog would dynamically populate a picklist when you open the tool. You're looking for something that pops up in the middle of the workflow, not first thing.

I'm not sure whether or not that can be done in model builder. I think it might be possible if you made it a python addin tool, but again, I don't have any experience with that, so I'm not sure.
0 Kudos