HOW TO

Add an Annotation FeatureClass from a Personal Geodatabase to ArcMap with ArcObjects

Last Published: April 25, 2020

Summary

Note:
This article pertains to ArcGIS versions 8.x. Later versions of ArcGIS may contain different functionality, as well as different names and locations for menus, commands and geoprocessing tools.

Instructions provided describe how to add an Annotation FeatureClass to ArcMap. In this example the annotation resides in a Personal GeoDatabase.

Note: 
Support for Visual Basic for Applications (VBA) for ArcMap and ArcCatalog ended with the ArcGIS 10.2.2 release, and Esri has not included VBA compatibility setups since version 10.5. See: ArcGIS Desktop and VBA Moving Forward

Procedure

  1. Start ArcMap.
  2. Create a new UIButtonControl: How To: Create a new UIButtonControl
Note:
 For more information on creating a UIControl, see the ArcGIS Desktop Help topic 'Creating custom commands with VBA and UI Controls'
  1. Right-click the UIButtonControl and select View Source.
  2. Copy below code into the UIButtonControl's click event.
Dim strPathName As String 
strPathName = "D:\temp\yellowstone.mdb" ' Replace with the name of your Personal Geodatabase
  1. Modify the value of strPathName to reflect the location of your personal geodatabase.
  2. Copy the code below into the UIButtonControl's click event, immediately after the code you entered in Step 4.
Dim strData As String 
strData = "AnnoRoad" ' Replace with the name of your annotation FeatureClass
  1. Modify the value of strData to point to the annotation Feature Class in your Personal Geodatabase.
  2. Copy the code below into the UIButtonControl's click event, immediately after the code you entered in Step 6.
' Set up the WorkspaceFactory
Dim pWorkspaceName As IWorkspaceName 
Set pWorkspaceName = New WorkspaceName 
pWorkspaceName.WorkspaceFactoryProgID = "esricore.AccessWorkspaceFactory" 
pWorkspaceName.PathName = strPathName 

Dim pDatasetName As IDatasetName 
Set pDatasetName = New FeatureClassName 

pDatasetName.Name = strData 
Set pDatasetName.WorkspaceName = pWorkspaceName 

' Use a lightweight Name object to open the table.
Dim pName As IName 
Set pName = pDatasetName  ' QI 

Dim pTable As ITable 
Set pTable = pName.Open 

Dim pFeatClass As IDataset 
Set pFeatClass = ptable 

Dim pFeatLay As IFeatureLayer 
'IFDOGraphicsLayerFactory::OpenGraphicsLayer IS THE KEY to accessing the data! 
Dim pFDOGraphicsLayerFactory As IFDOGraphicsLayerFactory 
Set pFDOGraphicsLayerFactory = New FDOGraphicsLayerFactory 

'*****************************************
' Modify this line of code
Set pFeatLay = pFDOGraphicsLayerFactory.OpenGraphicsLayer(pfeatclass.Workspace, Nothing, "AnnoRoad") 
'***************************************** 

'Assign the name in the Table of Contents 
pFeatLay.Name = pFeatClass.Name 

' Add the annotation to ArcMap
Dim pMap As IMap 
Dim pMxDoc As IMxDocument 

Set pMxDoc = ThisDocument 
Set pMap = pMxDoc.ActiveView 

pMap.AddLayer pFeatLay 

Dim pAV As IActiveView 
Set pAV = pMap 

pAV.Refresh 
  1. Modify the third argument passed to the OpenGraphicsLayer method to point to the input annotation Feature Class.
  2. Test the code.

Article ID:000004181

Software:
  • ArcMap 8 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic