You are here

ArcFM™ and Python

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

Author Information

  • Corey Blakeborough

    Corey Blakeborough

    Corey Blakeborough is a Senior Consultant at the Utility & Telecommunications GIS consulting company SSP Innovations in Centennial, Colorado. Corey has over five years of experience with SSP, providing a variety of GIS and work management solutions.

    See all items created by this author >

    Connect with me on:

Comments

Hey your ArcFM.py link is bad so this tutorial is useless.

James,

Thanks for your feedback. Our sincerest apologies for the broken link. The .py links have been fixed and tested.

-SSP

This is very helpful!

Add new comment