How to enable label abbreviation for a label class


This sample demonstrates how to programmatically enable label abbreviation for a label class. An abbreviation dictionary should already exist before this sample is run. The name of this abbreviation dictionary needs to be set in this sample where specified.

How to use

  1. Copy and paste the sample code into the VBA Editor.
  2. Run the Macro.
[VBA]
Public Sub TurnOnAbbreviationForALabelClass()
    
    Dim pMxDoc As IMxDocument
    Dim pGeoFL As IGeoFeatureLayer
    Dim pMap As IMap
    Dim pLayer As ILayer
    Dim pMaplexOverposterLayerProperties As IMaplexOverposterLayerProperties
    Dim pLabelEngineLayerProperties As ILabelEngineLayerProperties2
    Dim pAnnotateLPColl As IAnnotateLayerPropertiesCollection
    Dim pAnnotateLP As IAnnotateLayerProperties
    
    Set pMxDoc = ThisDocument
    Set pMap = pMxDoc.FocusMap
    
    'see if we are dealing with a Maplex map
    If TypeOf pMap.AnnotationEngine Is esriMaplex.IMaplexAnnotateMap Then
        
        Set pLayer = pMap.Layer(0)
        
        
        'get the first label class, qi to the Maplex properties and setup abbreviation
        'The abbreviation dictionary is stored in the MaplexOverposterProperties, but we just reference it by name here
        If TypeOf pLayer Is IGeoFeatureLayer Then
            Set pGeoFL = pLayer
            Set pAnnotateLPColl = pGeoFL.AnnotationProperties
            pAnnotateLPColl.QueryItem 0, pAnnotateLP, Nothing, Nothing
            Set pLabelEngineLayerProperties = pAnnotateLP
            Set pMaplexOverposterLayerProperties = pLabelEngineLayerProperties.OverposterLayerProperties
            pMaplexOverposterLayerProperties.DictionaryName = "Street Abbreviations" 'Change this to the name of your Dictionary created before hand
            pMaplexOverposterLayerProperties.CanAbbreviateLabel = True 'allow the layer to abbreviate
            
        End If
        
        
    Else
        'not a maplex map, do nothing
    End If
    
End Sub






Additional Requirements
  • The Maplex Extension must already be enabled, the data frame should be using Maplex, and an abbreviation dictionary should already exist.