Taking hold of the Python – Part 1

Esri have been phasing out VBA in favour of Python since ArcGIS 10.0.

Reason for transition – Microsoft has stopped supporting VBA. Since the release of ArcGIS 10, VBA was no longer recommended for use as it was not going to be included in subsequent versions, including 10.1. However it was still available in order to support legacy code and applications. A migration to Python, an open source programming language, was thus necessary.

Python is free, cross platform, open source, stable, mature, simple, and powerful. Benchmarking has shown that Python processes scripts in about a third of the time that VBA does.

Implementation in 10 & 10.1:

At ArcGIS 10, two new methods for customisation were introduced: Python scripting and the new ArcGIS Desktop Add-in.

Python scripting in ArcGIS was intended to automate time-consuming or complex workflows. It involves dealing with a geoprocessing framework built on top of ArcObjects, the building blocks of the ArcGIS products.  This geoprocessing framework creates a gentler learning curve for those users interested in learning how to automate workflows than with VBA which involved manipulating ArcObjects directly.

–        Python has been pervasive in ArcGIS 10.

–        It has replaced VB Script completely in the field calculator in 10.1.

–        The Python console replaces the Command Line window.

–        All geoprocessing tools are available as Python functions.

–        You can even copy Geoprocessing Results window entries and reuse the code in Python scripts.

–        Python scripts can access and update map documents and automate map printing and exporting.

–        You can write Python scripts to use as custom geoprocessing tools inside ArcGIS or as stand-alone scripts that call ArcGIS outside any ArcGIS application.

–        Using the new ArcPy Mapping module, you can access map documents in Python scripts.

ArcGIS 10.x come with the IDLE and PythonWin development environments. To help you efficiently create error-free scripts, both IDLE and PythonWin include syntax checking and code auto-complete once the ArcPy module has been imported into their interactive windows.

Add-ins have presented a new way to customize and extend ArcGIS 10 by adding tools on a toolbar, that plug into an ArcGIS for Desktop application (that is, ArcMap, ArcCatalog, ArcGlobe, and ArcScene) to provide supplemental functionality for accomplishing custom tasks. They have so far been authored in .Net or Java and Extensible Markup Language (XML). They have provided a declaratively based framework for creating a collection of customizations that can be conveniently packaged in a single compressed file that is easily shared without requiring installation programs or Component Object Model (COM) registration. However Python scripts could not be directly created into tools within the ArcMap interface.

The easiest way to integrate a Python script into ArcGIS since 9.3 was through a toolbox. As a workaround to include them as tools in a toolbar within ArcMap, you could:

  1. Call the script as a command line argument from another program that was linked to the button – the easiest would be VBA.
  2. Or add the Python script to the toolbox, and call the custom toolbox from your button (VBA, VB.Net, C#.Net).

However these were not really recommended solutions with the oncoming deprecation of VBA.

ArcGIS 10.1 introduces Python to the list of languages for authoring Desktop add-ins, providing you with an easy solution to extend desktop functionality. To simplify the development of Python add-ins, you must download and use the Python Add-In Wizard to declare the type of customization. The wizard will generate all the required files necessary for the add-in to work. Click here to download the Python Add-In Wizard.

Good luck taking hold of the Python!

Ricardo A

1 thought on “Taking hold of the Python – Part 1

  1. Riccardo Klinger

    Dear bloggers,

    My question is, how do the customers react on this transition? Most companies calculate most things with Excel so the VBA framework is very common…
    And a lot of companies are afraid of OpenSource…

    All the best from


Got something to say?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s