ArcFM™ and Python

April 9, 2012 — Corey Blakeborough

Last month, we presented you with a way to migrate scripts from VBA to Python as a means of reflecting the push away from Visual Basic in ArcGIS. The goal of the article was to continue to encourage scripting despite this change, and to be able to provide you with useful scripts in this new environment. To that end, we will be modifying our initial scripts and translating them to Python so that you will be able to utilize them regardless of the version of ArcGIS you happen to be running.

You will need a little background on this process before digging in. If you don’t know about installing comtypes on the machine you’ll be scripting with, for example, or you don’t know how to add a custom script to ArcToolbox, be sure to read the article on Python migration to get the full scoop.

Before we can massively convert our remaining VBA scripts for you, there’s an issue we haven’t yet discussed – using ArcFM™ with Python. ArcFM™’s COM objects are located elsewhere, so Snippets.py’s GetModule() function doesn’t actually work for ArcFM™ objects. We’ve created a new file that will allow ArcFM™ libraries to be imported.

ArcFM.py

We’ve released a new script called ArcFM.py that allows these scripts to easily interact with ArcFM™ objects. This will be necessary for certain scripts below. Download that here.

Move your newly-downloaded ArcFM.py to your appropriate ArcGIS Python folder – most likely something along these lines: C:\Python[version]\ArcGIS[version]\Lib\

You can access ArcFM™ components the same way as you would with ArcObjects components. First, start with an import:

    import ArcFM™

Then, just like snippets, use GetModule() to manually import a library. For example, to import the Miner & Miner Geodatabase Object Library:

    ArcFM.GetModule(“mmGeodatabase.olb”)

(For reference, you can find the folder name with all of the COM library files by running ArcFM.GetLibPath().)

Once you’ve retrieved the library, it’s available in comtypes.gen, alongside any ESRI objects you’ve imported via Snippets.py. For example, the Miner & Miner Geodatabase Object Library could be accessed via comtypes.gen.mmGeodatabase.

With this code, you can fetch and manipulate ArcFM™ objects using Python.

Example (Part 1: Do AU’s Get In the Way of Your Mass Updates?)

I’ve rewritten the original “useful script” to showcase this ArcFM™ functionality.

Toolbox Script:

Requires:

  • comtypes
  • Snippets.py
  • ArcFM.py

We Wrote the Book

The Indispensible Guide to ArcGIS Online

Download It for Free

Corey Blakeborough

Pre-Sales Architect

5 comments

What do you think?

Leave a comment, and share your thoughts

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


This site uses Akismet to reduce spam. Learn how your comment data is processed.