ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • Help
  • Sign Out
ArcGIS Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS Desktop

A complete professional GIS

ArcGIS Enterprise

GIS in your enterprise

ArcGIS for Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

ArcMap

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • Extensions

Accessing parameters in a script tool

  • sys.argv and arcpy.GetParameterAsText

The illustration below shows a script tool dialog box with three parameters: an input workspace, a clip feature class, and an output workspace. All feature classes in the input workspace are clipped to the clip feature class (using the Clip tool) and written to the output workspace.

Script tool parameters

In the illustration above, once parameter values have been entered on the tool dialog box and the OK button is clicked, the script reads the values of the parameters using GetParameterAsText(), as follows:

# Import arcpy site-package
#
import arcpy
from arcpy import env

# Read the parameter values:
#  1: input workspace
#  2: input clip features
#  3: output workspace
#
inWorkspace   = arcpy.GetParameterAsText(0)
clipFeatures  = arcpy.GetParameterAsText(1)
outWorkspace  = arcpy.GetParameterAsText(2)
env.workspace = inWorkspace

sys.argv and arcpy.GetParameterAsText

There are two methods for reading parameters: sys.argv and the arcpy function GetParameterAsText(). Either approach can be used. The example above could be rewritten to use sys.argv:

# Read the parameter values:
#  1: input workspace
#  2: input clip features
#  3: output workspace
#
inWorkspace   = sys.argv[1]
clipFeatures  = sys.argv[2]
outWorkspace  = sys.argv[3]
env.workspace = inWorkspace

sys.argv has limitations on the number of characters it can accept. GetParameterAsText() has no character limit. For this reason alone, it is recommended that you use GetParameterAsText.

sys.argv[0] returns the script file name.

Related topics

  • Setting script tool parameters
  • Understanding script tool parameters
  • What is a script tool?

ArcGIS Desktop

  • Home
  • Documentation
  • Support

ArcGIS Platform

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Esri Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
Copyright © 2020 Esri. | Privacy | Legal