Introduction
to ArcPy Scripting
What is ArcPy?
ESRI�s current environment that supports
editing and execution of Python scripts
They support other languages too but we won�t
be concerned with them in this course
There is also a universe of scripts in
abandoned languages�let them die�
Scripts must be written in Python version 2.7
(the version we�re learning in class)
For us, a script is one or more Python modules
that link with and call ArcPy modules to do stuff in
ArcGIS
Scripts are very useful because they allow you
to
Customize ArcGIS features for a specific set
of users,
Access ArcGIS features that are not currently
assigned to user interface controls,
Automate a set of frequently performed tasks,
and
Do combinations of all these things
Refer
to the instructions here to create toolboxes and scripts
All ArcPy scripts
link to ArcGIS functionality by including the following statement as one of the
first lines of executable code in a script:
import arcpy �# get the
spelling and case correct here!!
Once you have this line of code in your file,
you can call functions in the arcpy module like this:
arcpy.AddMessage('hello out there!')
# prints text in the console
AddMessage() is a function in the arcpy module
Please note: Since the arcpy module is only available when you are running your script from within
ArcGIS, this code will not run correctly from Eclipse, Sublime, or other python
environments outside of ArcGIS
Poking around in arcpy
arcpy is organized into functions and classes
It also contains submodules (like arcpy.mapping) that contain yet more functions and classes
You don�t have to memorize all this stuff!!
Learning arcpy scripting
We will start out by writing �hello world�
type scripts and then moving on to add real ArcGIS functionality
We will look at some existing scripts at ESRI and
from contributed source
As you start working on projects, you will
discover more functionality and get more ideas
Looking at other people�s scripts is a good
thing
Try to understand what the code
does�copying and pasting doesn�t help you at all
Copying without attribution is a bad
thing!
Always note where you got something if you
didn�t write the code yourself
At the least, this is just courteous to the original
authors
You don�t want to be accused of ripping off
someone else�s code