Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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:

  • the Direction in the Parameter Properties to Output;
  • the Data Type depending on what the Python output will be (probably a string or integer, but maybe a feature class);
  • and then the Type in the Parameter Properties to Derived (though to be fair, Required and Optional 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:

  • If you have the output parameter set to Required or Optional you can supply input to your script by providing default values, which you can get with arcpy.GetParameter or from sys.argv
  • The number of the parameter to set as output is dependent on the total number of parameters for your Python script (i.e. if you already have two input parameters before your output parameter then you need to use arcpy.SetParameter(2, value))

Also take a look at the arcpy Setting script tool parameters help.

share|improve this answer
    
Thanks a lot. I can't believe I never noticed the 'direction' property. –  Tom Oct 12 '12 at 16:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.