Create a Survey Dataset in ArcCatalog


This sample creates a survey dataset in ArcCatalog.

How to use:
  1. Start ArcCatalog.
  2. Select a geodatabase.
  3. Open VBA (Alt+F11 shortcut)
  4. Click Tools, and click references.
  5. Check the following ESRI Survey Analyst Library, and then click OK: ESRI Survey Analyst Object Library.
  6. Paste the code into VBA and run the subroutine called CreateSurveyDataset.
Private Sub CreateSDS()
'1.-->Get the selected object and make sure it's a geodatabase
  Dim pGXApp As IGxApplication: Set pGXApp = Application
  Dim pGXObject As IGxObject: Set pGXObject = pGXApp.SelectedObject
  If Not TypeOf pGXObject Is IGxDatabase Then
    MsgBox "Select a geodatabase"
    Exit Sub
  End If
'2.-->Get the Survey Analyst workspace extension  
  Dim pWS As IWorkspace: Set pWS = pGXObject.InternalObjectName.Open
  Dim pWSExtMan As IWorkspaceExtensionManager: Set pWSExtMan = pWS
  Dim pUID As New UID:  pUID.Value = "SurveyDatabase.SurveyDatabaseExtension"
  Dim pWsExt As IWorkspaceExtension: Set pWsExt = pWSExtMan.FindExtension(pUID)
'3.-->Define the Survey dataset extents with a new envelope      
  Dim pEnv As IEnvelope: Set pEnv = New Envelope
  pEnv.XMin = 0#: pEnv.XMax = 1000000#: pEnv.YMin = 0#: pEnv.YMax = 1000000#
'4.-->Define the Survey dataset spatial reference    
  Dim pSpatRefEnv As ISpatialReferenceFactory2: Set pSpatRefEnv = New SpatialReferenceEnvironment
  Dim prjFile As String: prjFile = "D:\SomeSpatialReference.prj"
  Dim pSpatRef As ISpatialReference
  Set pSpatRef = pSpatRefEnv.CreateESRISpatialReferenceFromPRJFile(prjFile)
  pSpatRef.SetDomain pEnv.XMin, pEnv.XMax, pEnv.YMin, pEnv.YMax
'5.-->Define the fields for the Survey dataset   
  Dim pField As IField, pFieldEdit As IFieldEdit, pFields As IFields, pFieldsEdit As IFieldsEdit
  Set pField = New Field: Set pFieldEdit = pField
  With pFieldEdit
    .Length = 30: .Name = "NamePrefix": .Type = esriFieldTypeString
  End With
  Set pFields = New Fields: Set pFieldsEdit = pFields
  pFieldsEdit.FieldCount = 1: Set pFieldsEdit.Field(0) = pField
'6.-->Set the Survey dataset extension   
  Dim pSurvDatasetExt As ISurveyDatasetExtension: Set pSurvDatasetExt = pWsExt
'7.-->Create the Survey dataset   
  Dim pSDS As ISurveyDataset
  Set pSDS = pSurvDatasetExt.CreateSurveyDataset("MyNewSDS", pSpatRef, pEnv, pFields, "")
'8.-->Refresh the view in ArcCatalog   
End Sub