Exporting the model and adjusting the script
While modeling analysis in ModelBuilder has its drawbacks, there is one fantastic option built into ModelBuilder: the ability to create a model, and then export the model to Python. Along with the ArcGIS Help Documentation, it is the best way to discover the correct Python syntax to use when writing ArcPy scripts.
Create a folder that can hold the exported scripts next to the SanFrancisco geodatabase (for example, C:\\ProjectsScripts
). This will hold both the exported scripts that ArcGIS automatically generates, and the versions that we will build from those generated scripts. Now, perform the following steps:
- Open up the model called
Chapter2Model1
. - Click on the
Model
menu in the upper-left side of the screen. - Select
Export
from the menu. - Select
To Python Script
. - Save the script as
Chapter2Model1.py
.
Note
Note that there is also the option to export the model as a graphic. Creating a graphic of the model is a good way to share what the model is doing...