Add a script tool

Creating a script tool allows you to turn your Python scripts and functionality into your own geoprocessing tools: tools that look and act like system geoprocessing tools.

To add a script tool to a toolbox, complete the following steps:

  1. Right-click the toolbox or toolset in which you want to create the script tool and click New > Script.

    The Tool Properties dialog box appears.

  2. In the list of side tabs, click the General tab.
  3. In the Name text box, type a name for the script tool.

    The name is used when the script tool is run from Python. Use only alphanumeric characters for the name.

  4. In the Label text box, type a label for the script tool.

    The label is the display name for the script tool (as shown in the Geoprocessing pane) and can contain spaces.

  5. In the Description text box, type a description for the script tool.
  6. If your toolbox is a Legacy toolbox (.tbx), check or uncheck the Store tool with relative path check box.

    If the option is checked (relative path), the Python file and toolbox file can be moved together, and the path to the Python file will be automatically updated. If the option is unchecked (absolute path), the path to the Python file will be maintained as is.

    If your toolbox is an ArcGIS toolbox (.atbx), this behavior is managed differently. If the script is in the same directory as the .atbx file or is in a child folder from where the .atbx is stored, a relative path is maintained. If the script and .atbx file are completely separate, an absolute path is maintained.

  7. In the list of side tabs, click the Parameters tab.

    The dialog box appears as follows:

    Define the script tool parameters
    1. Define the tool parameters in the Parameters tab.

      Almost all tools have input parameters, and all tools must have an output parameter to be used in ModelBuilder.

      To learn more about defining parameters, see Setting script tool parameters.

  8. In the list of side tabs, click the Execution tab.
    1. Type your Python code directly in the Execution tab.
    2. If encrypting your code is required, click the Encrypt button ロック解除 and then provide a password.
    3. Optionally, if you already have a script, click the Folder button フォルダー and browse to the location of your script.
  9. In the list of side tabs, click the Validation tab.

    Validation is everything that happens before a tool is run. Validation allows you to customize how parameters respond and interact to values and each other. Validation is performed with a block of Python code that can be used to give additional control over parameter behavior.

    To learn more about validation code, see Customizing script tool behavior.

  10. Click OK.

Your script tool is added to the toolbox. You can open and use it like any other geoprocessing tool. You can change any of its properties, including parameters, by right-clicking the script tool and clicking Properties.

関連トピック