You are here

Useful Scripts for the Non-Programmer: Where is My AU Configured?

ArcFM™ Autoupdaters are incredibly useful and widely used. Unfortunately, it can be difficult to keep track of them. There are many different potential reasons behind a need to find out where a specific AU is configured.

Today, we’re going to hand over an ArcCatalog VBA script that allows you to see the feature classes, subtypes, and events that any AU is assigned to. Simply run the script while selecting an open connection in ArcCatalog, input the display name of the AU in question, and you’ll be given a list of every location where that AU is configured.

NOTE: This script does not work for field-level autoupdaters or relationship autoupdaters, only for autoupdaters at the feature class level, though those scripts may appear in the future!

We should quickly mention that we’re matching the AU based on display name, so if you don’t know that by heart, you’ll need to know at least one location where the AU is configured to get the display name from the feature class’ ArcFM™ Properties window (alternatively, if you wrote the AU and have the code, you probably put it there too). An example is below:

useful-scripts-get-au-display-name

So here’s how we can make this work:

  • Open ArcCatalog.

  • Drop down the Tools menu and choose MacrosVisual Basic Editor.useful-scripts-vb-editor

  • Within the Visual Basic environment, expand the Normal.mxt file. Right-click it and insert a new Module within the Modules folder.

  • In the editor, click Tools → References and ensure that the following references are enabled:
    • Microsoft Scripting Runtime
    • Miner & Miner Geodatabase Object Library
    • Miner & Miner System Object Library

 useful-scripts-enable-microsoft-scripting-runtime

The code for this module is below, and it’s long! Copy and paste it into the module and save it.


Dim m_returnValues() As String
Dim
searchAUName As String
Dim
ac As Integer

Public Sub
FindConfiguredAUs()
    On Error GoTo EX

    ac = 0
    searchAUName = ""
    ReDim m_returnValues(0)

    Dim catalogApp As IGxApplication
    Set catalogApp = Application
    Dim ws As IWorkspace

    If TypeOf
catalogApp.SelectedObject Is IGxDatabase Then
        Dim
gdb As IGxDatabase
        Set gdb = catalogApp.SelectedObject
        If gdb.IsConnected Then
            Set
ws = gdb.Workspace
        End If
    End If

    If
ws Is Nothing Then
        ShowError "Please select a database connection to search for when running this function."
        Exit Sub
    End If


    searchAUName = InputBox("Enter the AU Display Name to search for:", "Find Autoupdater by Name")

    If Not searchAUName = "" Then
        Dim
eDS As IEnumDataset
        Set eDS = ws.Datasets(esriDatasetType.esriDTAny)
        IterateDatasets eDS

        Dim sb, i As Integer
        sb = "The '" & searchAUName & "' AU is configured in the following locations/subtypes:" & vbCrLf
        For i = 0 To UBound(m_returnValues)
            sb = sb & m_returnValues(i) & vbCrLf
        Next i

        Dim AUResultsFile As String
        AUResultsFile = "C:\Temp\AUResults" & DatePart("yyyy", Now) & "-" & Right("0" & DatePart("m", Now), 2) & "-" & Right("0" & DatePart("d", Now), 2) & " " & Right("0" & DatePart("h", Now), 2) & Right("0" & DatePart("n", Now), 2) & ".txt"

        Dim fso As Scripting.FileSystemObject
        Set fso = New Scripting.FileSystemObject
        Dim writer As TextStream
        Set writer = fso.CreateTextFile(AUResultsFile, True)
        writer.Write sb
        Shell "notepad.exe " & AUResultsFile, vbMaximizedFocus
        writer.Close
        Debug.Print sb
        fso.DeleteFile AUResultsFile, True
    End If
    Exit Sub

EX: ShowError "An error occured."
End Sub

Sub
IterateDatasets(pEnumDataset As IEnumDataset)
    Dim ds As IDataset

    pEnumDataset.Reset
    Set ds = pEnumDataset.Next
    Do While Not ds Is Nothing
        If
ds.Type = esriDatasetType.esriDTFeatureClass Then
            Dim
dfc As IObjectClass
            Set
dfc = ds
            ProcessObjectClass dfc

        ElseIf
ds.Type = esriDatasetType.esriDTTable Then
            Dim
doc As IObjectClass
            Set
doc = ds
            ProcessObjectClass doc

        ElseIf ds.Type = esriDatasetType.esriDTFeatureDataset Then
            IterateDatasets ds.Subsets
        End If
        Set
ds = pEnumDataset.Next
    Loop
End Sub

Sub ProcessObjectClass(oc As IObjectClass)
    If Not oc Is Nothing Then

        Dim ctl As IMMConfigTopLevel
        Set ctl = New MMConfigTopLevel

        Dim list As ID8List
        Dim sList As ID8List
        Dim listItem As ID8ListItem
        Dim sListItem As ID8ListItem

        Set mmFC = ctl.GetFeatureClassOnly(oc)
        Set list = mmFC

        list.Reset
        Set listItem = list.Next(False)
        Do While Not listItem Is Nothing
            If listItem.ItemType = mmd8ItemType.mmitSubtype Then
                Dim pSubtype As IMMSubtype
                Set pSubtype = listItem

                Set sList = listItem
                sList.Reset
                Set sListItem = sList.Next(False)
                Do While Not sListItem Is Nothing
                    If sListItem.ItemType = mmd8ItemType.mmitAutoValue Then
                        Dim autoValue As IMMAutoValue
                        Set autoValue = sListItem
                        If Not autoValue.AutoGenID Is Nothing Then
                            Dim UIDT As IMMUIDTools
                            Set UIDT = New MMUIDTools
   
                            Dim createdObject As Variant
                            Dim auName As String
   
                            Dim pAutoGenID As String
                            pAutoGenID = autoValue.AutoGenID
   
                            Set createdObject = UIDT.CreateFromClsidString(pAutoGenID)
                            auName = ""
   
                            If TypeOf createdObject Is IMMSpecialAUStrategy Then
                                Dim au1 As IMMSpecialAUStrategy
                                Set au1 = createdObject
                                auName = au1.Name
                            ElseIf TypeOf createdObject Is IMMSpecialAUStrategyEx Then
                                Dim au2 As IMMSpecialAUStrategyEx
                                Set au2 = createdObject
                                auName = au2.Name
                            ElseIf TypeOf createdObject Is IMMAttrAUStrategy Then
                                Dim au3 As IMMAttrAUStrategy
                                Set au3 = createdObject
                                auName = au3.Name
                            End If
   
                            If (Not auName = "") And LCase(Trim(auName)) = LCase(Trim(searchAUName)) Then
                                ReDim Preserve m_returnValues(ac + 1)
                                Dim sc As String
                                sc = pSubtype.SubtypeCode
                                m_returnValues(ac) = oc.AliasName & " (" & sc + ") " & sListItem.DisplayName
                                ac = ac + 1
                            End If
                        End If
                    End If
                    Set sListItem = sList.Next(False)
                Loop
            End If
            Set listItem = list.Next(False)
        Loop
    End If
End Sub


Sub
ShowError(msg As String)
    MsgBox msg, vbOKOnly, "SSP Find Configured AUs"
End Sub


When running the script, be sure that you have a connection open and you’ve selected it (it should be highlighted in ArcCatalog):

useful-scripts-ensure-open-connection

After that, you’ll have a nice list of every combination of feature class, subtype, and event for that AU.

useful-scripts-au-results

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

Just wanted to say thanks! This indeed is a VERY useful script.

Ed

Thanks for the feedback Ed! Will be sure to let Corey know...

Excellent tool for analysis :-)
This version requires that the object class has defined subtypes. Do you have a version that works independently of subtypes?

I went back and took a look at this and was able to make a quick update the code so that it includes object classes and supports classes with no subtypes. When an AU is configured on the "default subtype", it'll show as a "-1" value in the report. Hope this helps!

Thank you, this was absolutely excellent

Add new comment