The toolbox tools can all be converted into Python scripts. This is a great way to quickly learn Python in ArcGIS.
You can see that this is not the prettiest way to look at the code. In just a moment, we'll paste the same code into an IDE and it will be much more readable. Go ahead and press <enter>. This will run the buffer operation again but will produce an error because it is using the same name you just use. Now push the <up arrow> key and you should see the "Buffer_analysis" appear with just it's parameters in parenthesis. Go ahead and change the second "parameter", the file path for the output and then press <enter> again. The buffer operation should complete and place a new, buffered layer, into ArcGIS. You just modified and ran your first Python script in ArcGIS!
Warning: Not all of the Python functions available within Arc are available from an external IDE! In the example above "Buffer_analysis()" was used, but this function is only available through "analysis.Buffer()" when outside of the ArcGIS.
Tip: The "up" arrow allows you to access previous entries in the Python Window. You can also copy and paste text into the window to make it easier to execute lines of Python code.
You can go to any toolbox operation, open it, and click on the "Help" button to see information on the operation. If you scroll down, you'll see the definition of the Python function for the operation and the parameters you can send to the function.
If you don't know the name of a toolbox tool, or you're looking for help on a Python function that is not in the toolbox, you can check the "ArcGIS Desktop Help".
Here you will find a description of the Python function call to execute a buffer transform. This help is a great way to learn about the Python functions that are equivalents to the ArcGIS transform (toolbox functions).
Another way to get help is through the Python window.
This is not as helpful as might first appear because there are a huge number of functions, it's easier to find a function through the Toolbox.
The combination of IDLE in ArcGIS and the help you've just seen could be used to write Python programs in ArcGIS. However, this development environment is very limited and makes it hard to create programs and especially to learn to program.
Take the code snippet from our "Buffer" tool above a paste it into a new file in the Wing IDE. There are two changes you'll need to make to get this code to run:
Run the script and see if it works. You may need to change the output file path as ArcGIS will not overwrite an existing file. Now try changing some of the parameters and see what effect this has.
The "Using Python in ArcGIS Desktop 10" tutorial from ESRI starts off great but then gets very detailed very quickly. It also did not show the entire video area for me on IE but did work correctly in FireFox. Also, the transcript gave a postscript error when I tried to open it.
There is some excellent online help from ESRI's website starting at What is Python? Take a look around this help section and the one below it called The ArcPy Package. The both have great information on how to use Python in ArcGIS.
© Copyright 2018 HSU - All rights reserved.