How to create subtypes for an object class


Subtypes are a way that you can group features or objects within a feature class or object class. By assigning different default values and validation rules for the subtypes you can maintain the flexibility of the feature class while increasing the customization of your features. To establish subtypes for an object class and the default values for a subtype's fields, you use the ISubtypes interface on the object class. In the sample code below, a feature class called 'Buildings' is assigned the following subtypes:
Building (subtype code 0)
Commercial (subtype code 1)
Residential(subtype code 2)
 
The subtype column will be SYMBOL. Once the subtypes are created, the TYPE_ field is assigned default values for each subtype.

How to use

  1. In ArcCatalog, open the Properties dialog on the feature class into which the subtypes will created.
  2. If subtypes aleady exist, delete them by setting the subtype field to None. Close the dialog with OK.
  3. Change the pathname, feature dataset, feature class, subtype field and subtypes accordingly.
  4. Paste the code into your VBA Application and run it.
[VBA]
Sub Add_subtypes()
    ' open the workspace
    Dim pFact As IWorkspaceFactory
    Set pFact = New AccessWorkspaceFactory
    
    Dim pWorkspace As IWorkspace
    'Open workspaces *** Modify the pathname appropriately.
    Set pWorkspace = pFact.OpenFromFile("D:\Data\Geodatabases\MyGDB.mdb", 0)
    
    ' get the dataset
    Dim pFeatws As IFeatureWorkspace
    Set pFeatws = pWorkspace
    
    Dim pFeatds As IFeatureDataset
    '*** Modify the feature dataset name appropriately.
    Set pFeatds = pFeatws.OpenFeatureDataset("SNLandbase")
    
    Dim pFeatclscont As IFeatureClassContainer
    Set pFeatclscont = pFeatds
    
    ' open the feature class
    Dim pFeatcls As IFeatureClass
    '*** Modify the feature class name appropriately.
    Set pFeatcls = pFeatclscont.ClassByName("SNBuildings")
    
    ' QI for the ISubtypes interface
    Dim pSubType As ISubtypes
    Set pSubType = pFeatcls
    
    ' Assign SYMBOL as the subtype field if not already setup. *** Modify the subptype name appropriately.
    If pSubType.SubtypeFieldName = "SYMBOL" Then Exit Sub
    pSubType.SubtypeFieldName = "SYMBOL"
    
    ' Add subtypes. *** Modify the subptypes appropriately.
    pSubType.AddSubtype 0, "Building"
    pSubType.AddSubtype 1, "Commercial"
    pSubType.AddSubtype 2, "Residential"
    
    ' Assign the default subtype code. *** If needed, change the default subtype.
    pSubType.DefaultSubtypeCode = 0
    
    ' Set default values for some fields for each subtype. *** Change the field anme and default appropriately.
    pSubType.DefaultValue(0, "TYPE_") = "BLD"
    pSubType.DefaultValue(1, "TYPE_") = "COM"
    pSubType.DefaultValue(2, "TYPE_") = "RES"
    
    MsgBox "Done"
End Sub






Additional Requirements
  • Two Geodatabases, with the origin Geodatabase containing a feature class with subtypes.