6

How do you add an output parameter in a python script in a toolbox?

2 Answers 2

11

This was a simple question that had found difficult to answer. I searched through the Esri documentation, which is usually very thorough, but just overlooked it. I wanted to share my answer here in a concise manner.

  • In the Parameters dialog, set up a parameter, and set its direction to "output". Set the type to "Derivative" if applicable.

  • In the script, use the following command to pass the the feature set/value as output ("1" here is the index for the parameter):

  • arcpy.SetParameter(1, OutFeatureSet)

(Thanks to Mark's question on the Esri Forums for pointing me to the correct answer! https://geonet.esri.com/thread/57822)

1

If your input will be the same as your output then you don't need to add a parameter in your code; just create a parameter in your tool and set as you referenced. The obtained from property of the output should be set to your input parameter. This will create an output result to use add an input in model builder. Also, in your code, set your environment for overwrite to true.

https://gisnuts.com/terra/blog/2012/09/05/5-tips-for-writing-python-script-tools-applied-to-an-autonumber-tool

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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