How to create a new Maplex abbreviation dictionary


This sample demonstrates how to programmatically create a new Maplex Abbreviation Dictionary and how to add entries to it. The data frame should already be using the Maplex Label Engine before running this sample.

How to use

  1. Copy and paste the sample code into the VBA Editor.
  2. Run the Macro.
[VBA]
Public Sub CreateNewDictionary()
    
    Dim pMxDoc As IMxDocument
    Dim pMap As IMap
    Dim pMapOverposter As IMapOverposter
    Dim index As Long
    Dim pMaplexOverposterProperties As IMaplexOverposterProperties
    Dim pDictionaries As IMaplexDictionaries
    Dim pDictionary As IMaplexDictionary
    Dim pDictEntry As IMaplexDictionaryEntry
    
    Set pMxDoc = ThisDocument
    Set pMap = pMxDoc.FocusMap
    
    'Make sure we have a maplex map here
    If TypeOf pMap.AnnotationEngine Is esriMaplex.MaplexAnnotateMap Then
        
        Set pMapOverposter = pMap
        
        Set pMaplexOverposterProperties = pMapOverposter.OverposterProperties
        Set pDictionaries = pMaplexOverposterProperties.Dictionaries
        Set pDictionary = New MaplexDictionary
        pDictionary.Name = "Sample Street Dictionary"
        
        'to simplify adding entries, call the helper function CreateDictionaryEntry below to create and hand back entries
        pDictionary.AddEntry CreateDictionaryEntry("Street", "St", esriMaplexAbbrevTypeEnding)
        pDictionary.AddEntry CreateDictionaryEntry("Avenue", "Ave", esriMaplexAbbrevTypeEnding)
        pDictionary.AddEntry CreateDictionaryEntry("Court", "Ct", esriMaplexAbbrevTypeEnding)
        
        'add the dictionary to the dictionaries collection
        pDictionaries.AddDictionary pDictionary
        
        'add the dictionaries collection to the Overposter properties
        pMaplexOverposterProperties.Dictionaries = pDictionaries
        
    End If
    
End Sub

Public Function CreateDictionaryEntry(ByVal Keyword As String, ByVal Abbreviation As String, ByVal Abbrevtype As esriMaplexAbbrevType) As IMaplexDictionaryEntry
    
    Dim pMaplexDictionaryEntry As IMaplexDictionaryEntry
    Set pMaplexDictionaryEntry = New MaplexDictionaryEntry
    
    pMaplexDictionaryEntry.Abbreviation = Abbreviation
    pMaplexDictionaryEntry.Text = Keyword
    pMaplexDictionaryEntry.Type = Abbrevtype
    
    Set CreateDictionaryEntry = pMaplexDictionaryEntry
    
End Function






Additional Requirements
  • The Data Frame should already be using the Maplex Label Engine