Home arrow GIS Data & Resources arrow Scripts and Code arrow Visual Basic / VBA arrow VBA: Check ArcSDE Registered-As-Versioned Status
VBA: Check ArcSDE Registered-As-Versioned Status PDF Print E-mail

Written by Bert Granberg,

This code can be used to check and update your ArcSDE feature classes and feature datasets in 'Registered As Versioned' mode.

It will check the registered as versioned status for all selected feature datasets and standalone feature classes and produce a report in a time-stamped text file.

Where possible -- if your connection user is the owner of the data AND there are no existing read locks -- the script will register FC's and FDS's as versioned that are not so already.

To use:
  1. Paste the code below into ArcCatalog's VBA Editor(F11 --> View --> Project Explorer -->ArcCatalog Objects-->ThisDocument)
  2. Select SDE feature classes or feature datasets from the Contents tab in ArcCatlog (not to be confused with the tree view
  3. Run the subprocedure named VersionSDEDatasets

Private Sub VersionSDEDatasets()

    Dim outputLocation  as String
    outputLocation = "c:\temp\"
    
    Open outputLocation & "unregistered_logfile_" & Format(Now, "yymmddhhmm") & ".txt" For Output As #1

    Dim pGxApp As IGxApplication
    Dim pSelGxObject As IGxObject
    Dim pGxSel As IGxSelection
    Dim pEnumGxObjSel As IEnumGxObject
    Dim isVersioned As Boolean
    
    Set pGxApp = Application
    Set pGxSel = pGxApp.Selection
    Set pEnumGxObjSel = pGxSel.SelectedObjects
    pEnumGxObjSel.Reset
    Set pSelGxObject = pEnumGxObjSel.Next
    
    Do Until pSelGxObject Is Nothing
        If pSelGxObject.Category = "SDE Feature Class" Then
            isVersioned = checkVersioned(pSelGxObject, True)
            Debug.Print isVersioned & " " & pSelGxObject.FullName
            Print #1, isVersioned & " " & pSelGxObject.FullName
        ElseIf pSelGxObject.Category = "SDE Feature Dataset" Then
            Dim pGxObjContainer As IGxObjectContainer
            Dim pEnumGxObj As IEnumGxObject
            Dim pCurrGxObject As IGxObject
            Set pGxObjContainer = pSelGxObject
            
            isVersioned = checkVersioned(pSelGxObject, True)
            Debug.Print isVersioned & " " & pSelGxObject.FullName
            Print #1, pSelGxObject.FullName
            
            If pGxObjContainer.HasChildren Then
                Set pEnumGxObj = pGxObjContainer.Children
                If Not pEnumGxObj Is Nothing Then
                    Set pCurrGxObject = pEnumGxObj.Next
                    Do Until pCurrGxObject Is Nothing
                        If pCurrGxObject.Category = "SDE Feature Class" Then
                            isVersioned = checkVersioned(pCurrGxObject, False)
                            Debug.Print "  " & isVersioned & " " & pCurrGxObject.FullName
                            Print #1, "  " & isVersioned & " " & pCurrGxObject.FullName
                        End If
                        Set pCurrGxObject = pEnumGxObj.Next
                    Loop
                End If
            End If
        End If
        Set pSelGxObject = pEnumGxObjSel.Next
    Loop
    Close #1
    Close #2
End Sub

 

Public Function checkVersioned(inGxObj As IGxObject, register As Boolean) As Boolean

    On Error GoTo ErrorHandler

    'Get the selected Dataset
    Dim pGxApp As IGxApplication
    Set pGxApp = Application
    Dim pgxDataset As IGxDataset
    Dim pDataset As IDataset
    Dim pVersionedObject As IVersionedObject
    
    If TypeOf inGxObj Is IGxDataset Then
        Set pgxDataset = pGxApp.SelectedObject
        Set pDataset = pgxDataset.Dataset
        Set pVersionedObject = pDataset
        If pVersionedObject.IsRegisteredAsVersioned Then
            checkVersioned = True
        Else

            checkVersioned = False
            
            If register Then
                checkVersioned = True 'as it will be newly versioned
                pVersionedObject.RegisterAsVersioned True
            End If
                    
        End If
    End If

    Exit Function

ErrorHandler:
    'Feature Dataset Locked!!
    checkVersioned = False
    Debug.Print "LOCKED " & inGxObj.FullName
    Print #1, "LOCKED " & inGxObj.FullName
    Resume Next

End Function


Users' Comments  
 

No comment posted

Add your comment

24, Nov. 2008
Last Updated ( 24, Nov. 2008 )
 
< Prev   Next >

AGRC Contacts | UGIC Contacts

feed image feed image

Utah GIS Portal © 2009 AGRC

Optimized for