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:
- 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.
- In the list of side tabs, click the General tab.
- 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.
- 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.
- In the Desription text box, type a description for the script tool.
- 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.
- In the list of side tabs, click the Parameters tab.
The dialog box appears as follows:
- 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.
- Define the tool parameters in the Parameters tab.
- In the list of side tabs, click the Exection tab.
- Type your Python code directly in the Execution tab.
- If encrypting your code is required, click the Encrypt button and then provide a password.
- Optionally, if you already have a script, click the Folder button and browse to the location of your script.
- 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.
- 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.
Rubriques connexes
Vous avez un commentaire à formuler concernant cette rubrique ?