Scripting/Automating/ Customizing ArcGIS
And other ways of streamlining your workflow Tom Schwartzman ESRI Boston July 13, 2005
Goals
Learn about:
Geoprocessing (automation) Scripting (automation) Customizing
Expectations
Were not going write code today We will look at some samples and learn how to install them This is basic/intermediate user-level
Geoprocessing Framework
Tools Commands Models Scripts Analysis platform Flexible Extendable
ArcToolbox
A dockable window in ArcMap and ArcCatalog
ArcToolbox
Can create your own toolboxes
Store on disk or in a geodatabase Holds tools and models Can be shared with others
The Command Line
Its back, and has intellisense
Using Modelbuilder
Models are created in the Modelbuilder window Color coded by object type
Data Tool Result
Models can be converted to scripts
Python vbScript Jscript
Run processes in batch
Modelbuilder Functionality
Models can be made flexible with parameters that can be input at run time Variables can hold user defined constants Tests of conditions can be used for branching Preconditions can be set on processes Models can call other Models
Adding Data
Add feature classes to model
Drag and Drop Add from file system Add Layer from ArcMap
Adding Tools
Add tools to model
Drag and Drop from Toolbox
Connect pieces
Model Parameters
Data and variables can be used as model parameters
Data to be input at run time Data to be output at the end to another destination
Variables and Preconditions
Variables hold constant values, or can be set as parameters Preconditions determine the order of execution for processes
Drawn in diagram with a dashed line
Export from Modelbuilder
Models can be converted to scripts
Python vbScript Jscript
Scripts cannot then be exported back to models Modified Script can then be added as a Script Tool in a toolbox
Introduction to Python
Free and powerful scripting language Can do many tasks in addition to working with the geoprocessing (gp) framework Python Page http://www.python.org Microsoft Page http://www.microsoft.com/technet/scriptcenter/sc ripts/python/default.mspx contains list of Windows samples scripts Easy to learn, simple syntax Lots of good books out there
OReilly Press: Learning Python good for beginners OReilly Press: Programming Python good reference Interactive execution window: PythonWin Basic development environment: IDLE Widely accepted scripting language
The Python scripting language
What is Python?
An open-source, object-oriented, scripting language
Can view and modify source code Easy to use
Python Python script script
Why use Python?
Offers IDEs with debugging tools Modular, can be broken apart Cross platform Ability to compile scripts Installed with ArcGIS 9 and ESRI samples provided
Writing Python Scripts
Python scripts can be written in Notepad, or any text editor, free, shareware, or paid
TextPad UltraEdit Komodo
PythonWin and IDLE come with the installation Samples use PythonWin
Environments to write, save, run, and debug code
User Interface Customization
Toolbars and some windows are dockable Double click title to autodock/undock Hold CTRL key down to avoid auto-docking
Toolbars
Change locations of buttons/tools, delete/add buttons/tools Create your own toolbar with your choice of buttons/tools Available by using Customize dialog
Tools Customize Double-click in empty area of toolbar Right-click and choose Customize
Toolbars contd
Toolbars
Lots of useful buttons/tools exist but are not on any toolbar. Examples:
Clear Selected Zoom to Selected Continuous Zoom
Samples
Lots of samples out there from:
ESRI (Developer Kit CD, online http://edn.esri.com) Users (http://arcscripts.esri.com)
Some are VBA scripts (pasted into VBA editor in ArcMap) and run from a button-click
Samples
Some are simply added using Add from file in the Customize Dialog
Samples
Some come with an installer of some sort (batch file, exe, etc) And some need more help getting registered.
Regsvr32.exe to register the compiled .dll with the system Categories.exe to tell ArcGIS what part of the system it belongs in (e.g. sketch tool, renderer, etc)
Hopefully this is documented with the sample!
Templates
Predefined map layouts that can be imported into your current doc Your layout will change to match the template
You may lose/gain elements (legend, north arrow, etc) You wont lose data
Training
Instructor Led:
Intro to ArcObjects: Aug 15-19 Intro to Python: Sep 8-9
Virtual Campus:
Customizing ArcGIS 9 Customizing ArcMap Exploring VBA Working with Forms in VBA Working with Variables and Functions in VBA
Training
Instructor Led:
Intro to ArcObjects: Aug 15-19 Intro to Python: Sep 8-9
Virtual Campus:
Customizing ArcGIS 9 Customizing ArcMap Exploring VBA Working with Forms in VBA Working with Variables and Functions in VBA Getting Started with Scripting (free)