FeatureClassDraw

Created:03/26/2002
Description:

One purpose of writing a Geodatabase Feature Class Extension is to define define default symbology for a given feature class when added to ArcMap. This symbology is also used when the feature class is previewed in ArcCatalog. To gain this functionality, write a Feature Class Extension that implements IFeatureClassDraw. In IFeatureClassDraw::CustomRenderer you set the default FeatureRenderer to be used for the feature class. In this sample, the CustomRenderer is an ESRI renderer, however it could just as easily be a custom renderer.

This sample consists of the class extension that defines default rendering for a polygon Geodatabase feature class. The assigned default renderer is an ESRI UniqueValueRenderer. Also included is a simple VBA macro. You must run this macro in ArcCatalog to insert the GUID (Global Unique IDentifier) for your class extension into the the USA Geodatabase's ObjectClasses table for the states feature class. This is the one and only association between the class extension and the states feature class.

Also of interest is IFeatureClassDraw::ExclusiveCustomRenderer. Return True for this member to prevent users from changing to a different layer symbology method through the ArcMap GUI.


How to use:
  1. Register this sample's dll by compiling the sample or by using Regsvr32.exe.
  2. Start ArcCatalog.
  3. Go to Tools > Customize > Commands. Select UIControls from the left pane and click New UI Control.
  4. Make sure UIButtonControl is selected and click Create. Drag and drop the new button control onto one of the ArcCatalog toolbars.
  5. Right click on the button and select View Source. Paste in the following VBA code:
    
    Private Sub AddValClassExten_Click()
     
      Dim pGxApp As IGxApplication
      Dim pGxDataset As IGxDataset
      Dim pClassSchemaEdit2 As IClassSchemaEdit2
      Dim pEXTCLSID As UID
      
      Set pGxApp = Application
      If pGxApp.SelectedObject Is Nothing Then
        MsgBox "Select FeatureClass"
        Exit Sub
      End If
      
      If Not TypeOf pGxApp.SelectedObject Is IGxDataset Then
        MsgBox "Select FeatureClass"
        Exit Sub
      End If
      
      Set pGxDataset = pGxApp.SelectedObject
      Set pClassSchemaEdit2 = pGxDataset.Dataset
      
      Set pEXTCLSID = New UID
      pEXTCLSID.Value = "FeatureClassDraw.ClassExten"
      pClassSchemaEdit2.AlterClassExtensionCLSID pEXTCLSID, Nothing
      MsgBox "Updated " & pGxDataset.Dataset.Name & " to " & pEXTCLSID.Value
    End Sub
    		
  6. Close the VBA Editor.
  7. In ArcCatalog navigate to the ArcObjects Developer Samples sample data (c:\arcgis\arcexe82\ArcObjects Developer Kit\Samples\Data\usa).
  8. Select the states feature class and click on the UIButton you created above. You should see an ArcCatalog message that says, "Updated states to ..." .
  9. Open ArcMap and drag and drop states in from ArcCatalog. The layer is symbolized with the UniqueValueRenderer defined in the Class Extension.
  10. Finally, double click on the states layer in ArcMap to open the Layer Properties dialog. Click the symbology tab. Notice that part of the GUI is locked, and the user is prevented from selecting a different renderer.

Application:
ArcMap,ArcCatalog

Requires: ArcMap,ArcCatalog,USA Geodatabase from ArcObjects Developer Sample data.

Difficulty: Intermediate


Visual Basic
File Description
ClassExten.cls Class extension class.
FeatureClassDraw.vbp Visual Basic project file.
FeatureClassDraw.dll The compiled component.


Key CoClasses: UniqueValueRenderer
Key Interfaces: IClassHelper, IClassExtension, IFeatureClassDraw
Key Members: IFeatureClassDraw::CustomRenderer, IFeatureClassDraw::ExclusiveCustomRenderer