Edit 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 sample is part of the Illustrated Code Samples found in Appendix C of the ArcGIS Desktop Developer's Guide. These samples show you the fundementals of programming COM components in ArcObjects.

Start by entering the VBA environment in ArcMap or ArcCatalog and type in the code. Step through the code in the VBA debugger. Look at the sample in Appendix C of the ArcGIS Desktop Developer's Guide and study the relationships between coclasses and interfaces.

A careful reading of the samples in the appendix gives you all the important concepts you need for developing with ArcObjects, as well as an introduction to the most important ArcObjects components.
ArcView: VBA

Platforms: Windows

Minimum ArcGIS Release: 9.0

How to use:
  1. Add the code to the Click event of a command in ArcCatalog.
  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

  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

  Exit Sub
    MsgBox "Unable to obtain exclusive database lock", vbExclamation + vbOKOnly, "Database Lock Error"
    MsgBox "Unknown error getting schema lock", vbExclamation + vbOKOnly, "Database Error"
  End If