I have a model that passes a variable to a python script. The script uses that variable to query some directories and return a list of paths. What I want to know is:
- How can I then use each of those paths as the parameter in a subsequent operation?
- Is the bridge between python and ModelBuilder a one-way street?
Best Answer
I assume that you've added the Python script to the model by first adding the Python script to the toolbox, setting the script input through the Parameters tab.
In the Parameters tab you can add new parameters for the script output. To do this simply change:
Direction
in the Parameter Properties toOutput
;Data Type
depending on what the Python output will be (probably a string or integer, but maybe a feature class);Type
in the Parameter Properties toDerived
(though to be fair,Required
andOptional
will work depending on the data type, but I'll describe that below)Then we can simply use
arcpy.SetParameter
to output from your Python script back to the model.A couple of notes:
Required
orOptional
you can supply input to your script by providing default values, which you can get witharcpy.GetParameter
or fromsys.argv
arcpy.SetParameter(2, value)
)Also take a look at the arcpy Setting script tool parameters help.