How to edit the feature class schema


This code sample inspects the selected objects in the ArcCatalog browser and if they are feature classes in a geodatabase, makes an edit to their alias name.
The code samples in this section show the fundamentals of programming with ArcObjects. A careful reading of them gives you all the important concepts you need for developing with ArcObjects, as well as an introduction to the most important ArcObjects components.
The code can be typed or copied into the VBA environment in ArcMap or ArcCatalog, after which you can follow through with the VBA debugger.

How to use

  1. Add the code to the Click event of a command in ArcCatalog.
[VBA]
Dim pGxApp As IGxApplication
Set pGxApp = Application

Dim pGxCatalog As IGxCatalog
Set pGxCatalog = pGxApp.Catalog

Dim pGxSelection As IGxSelection
Set pGxSelection = pGxCatalog.Selection

Dim pGxObjects As IEnumGxObject
Set pGxObjects = pGxSelection.SelectedObjects
pGxObjects.Reset

Dim pGxObject As IGxObject
Set pGxObject = pGxObjects.Next

If (pGxObject Is Nothing) Then Set pGxObject = pGxCatalog.SelectedObject

Dim pGxDataset As IGxDataset
Dim pObjectClass As IObjectClass
Dim pClassSchemaEdit As IClassSchemaEdit
Dim pSchemaLock As ISchemaLock
Do Until (pGxObject Is Nothing)
    If (TypeOf pGxObject Is IGxDataset) Then
        Set pGxDataset = pGxObject
        If ((pGxDataset.Type = esriDTFeatureClass) And _
            (pGxDataset.Dataset.Workspace.Type <> esriFileSystemWorkspace)) Then
            Set pObjectClass = pGxDataset.Dataset
            Set pSchemaLock = pObjectClass
            
            Set pClassSchemaEdit = pSchemaLock
            On Error GoTo lockDB
            pSchemaLock.ChangeSchemaLock esriExclusiveSchemaLock
            On Error GoTo 0
            pClassSchemaEdit.AlterAliasName "ArcObjects Updated Alias"
            
            pSchemaLock.ChangeSchemaLock esriSharedSchemaLock
        End If
    End If
    Set pGxObject = pGxObjects.Next
Loop

Exit Sub
lockDB:
If (Err.Number = FDO_E_SCHEMA_LOCK_CONFLICT) Then
    MsgBox "Unable to obtain exclusive database lock", vbExclamation + vbOKOnly, "Database Lock Error"
Else
    MsgBox "Unknown error getting schema lock", vbExclamation + vbOKOnly, "Database Error"
End If
Err.Clear