Arcpy scripts
Finally, let us run our script from ArcToolbox.
Copy your script and call it explosionscript.py. Have a go, based on the last practical, at getting the script into the Models toolbox as a script and making it work with parameters.
What we're doing here is different from last time. Last time we exported the model as a script and got the individual
geoprocessing tool components working in a script as Python. Here we're running the model as a tool. Remember you need to
import the script, and set up its parameters in its properties. You'll need to replace the parameters hardwired into the
model with variables, and use getParameter
to draw the parameters from the GUI. Note that the order of the
parameters matters as things are.
Add some print statements to provide the user and developer with some useful messages saying how the script is progressing, and change the exception catching so it prints the stacktrace as well as the Error messages.
Once you've got that working, we're done for this practical. Here's some extra stuff you can do if you have time:
- Add a description: this helps when users search for the tool in Arc. The search tab is usually down the right-hand side of ArcMap. You can add a description by right-clicking the Script and choosing Item Description... -> Edit. You then need to add the toolbox directory to the system. The simplest way to do this is search for something that doesn't exist, at which point the search dialog will give you the chance to open the Search Options under which you can register a folder and index new items. After this, searching for the tool should bring up the description.
- Attach the script to a menu item: this saves the user finding the toolbox. See "Adding a custom tool to a menu or toolbar" on this page.
- Build a full Python toolbox.