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 am running set of processes each with different outputs in a python script. Is there a way to set a variable as global so that just the output of that single step can be accessed from other scripts?

share|improve this question

2 Answers 2

Script tools, like other geoprocessing tools, are meant to be able to be chained together in ModelBuilder, the Python window or other scripts/script tools. You can set up output parameters that you can access as output nodes in ModelBuilder, or as result values within the Result object in a script.

Output Parameters in ModelBuilder

Output parameters can be set directly as part of the user-exposed parameters, derived from an input parameter, or derived within the script. If it is derived within the script, you can use SetParameterAsText() to set the output value within the script.

If you have a homogenous set of data elements (tables, feature classes, etc.) being output by your script, you could use a multi-value output parameter and set it by joining the items with semicolons, e.g. arcpy.SetParameterAsText(1, ';'.join(outputvalues)).

You could then split those semicolon-delimited values into a list and iterate over it in a subsequent script tool using, e.g. inputvalues = arcpy.GetParameterAsText(0).split(';'), use an Iterate Multivalue iterator in ModelBuilder, or simply pass the multivalue parameter directly to a tool or function that supports them.

Hope that gives you some idea of the possibilities!

share|improve this answer
    
'Obtained from' option seems what i am looking for to pass variables to and fro between codes. Thanks! –  Ibe Oct 27 '12 at 23:33
    
Not necessarily. Read more about the "Obtained from" setting here: help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//… –  blah238 Oct 27 '12 at 23:38

This very much depends on your python programming skills. Pyton has sophisticated ways of handling variables between functions.

The simplest way of handling variables could be to write the variable to a file. The variable is then picked up by the other script.

Since you probably are using arcpy with shapefiles, why not use arcpy to either manipulate the contents of your shapefile dbf, or just a plain dbf-file?

share|improve this answer
    
Thanks for suggestion. My work involve converting some of the avenue codes into python. Codes in avenue are talking to each other and passing variable values which is what i want to achieve with python. I think writing all function values to a file and calling them at need will be easy structure approach. I'll give it a try! –  Ibe Oct 27 '12 at 23:29

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.