Edit Feature Class Schema



Description:

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.
Products:
ArcView: VBA

Platforms: Windows

Minimum ArcGIS Release: 9.0

How to use:
[VBA]
  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
  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