English

Problem: Annotation is not rotating when the data frame is rotated

Description

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

Text annotation in ArcMap is not rotating when the Rotate Data Frame Tool is used. This can happen with both Geodatabase annotation and with annotation stored in the map.

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

Cause

Some ArcGIS annotation does not rotate with the data frame. This includes some annotation created in earlier versions of ArcGIS. This means that when the Data Frame Rotate tool is used, the annotation does not rotate along with the data.

Solution or Workaround

In ArcGIS version 8.3 and later, run a VBA code to modify the annotation so it rotates when the data frame is rotated.

Note:
The reverse is also possible: to make annotation that rotates with the data frame, remain stationary.

Follow the steps below.

  1. Open a new ArcMap document and add the annotation, if there is geodatabase annotation present. If there is map annotation present, open the map document that contains the annotation.
  2. Open the Visual Basic Editor, from the Tools menu in ArcMap, and add the following code:
Option Explicit

Const ROTATE_WITH_TRANSFORM = True

Public Sub SetAnnotationRotateFlag_Geodatabase()
'   1. Start Editing
'   2. Select Geodatabase annotation features using Edit tool
'   3. Change Const value above to either True or False (True = rotate text when dataframe rotates)
'   4. Run this code
'   5. Stop Editing, Save Edits
    
    Dim pEditor As IEditor
    Dim pID As New UID
    Dim pEnumFeature As IEnumFeature
    Dim pFeature As IFeature
    Dim Count As Long
    Dim pActiveView As IActiveView
    
    pID = "esriCore.Editor"
    Set pEditor = Application.FindExtensionByCLSID(pID)
    
    pEditor.StartOperation
    Set pEnumFeature = pEditor.EditSelection
    pEnumFeature.Reset
    
    Dim pElement As IElement
    Dim pAnnoF As IAnnotationFeature
    Dim pTextElement As ITextElement
    Dim theAnnoString As String
    Dim stringToReplace As String
    Dim replacementString As String
    Dim pTextSym As ITextSymbol
    Dim pSymRot As ISymbolRotation
    
    Set pFeature = pEnumFeature.Next
    Do Until pFeature Is Nothing

        Set pAnnoF = pFeature
        Set pElement = pAnnoF.Annotation
        
        'only work with text elements
        If TypeOf pElement Is ITextElement Then
            Set pTextElement = pElement
            Set pTextSym = pTextElement.Symbol
            Set pSymRot = pTextSym
            
            pSymRot.RotateWithTransform = ROTATE_WITH_TRANSFORM
            
            pTextElement.Symbol = pTextSym
            pAnnoF.Annotation = pElement
            Set pFeature = pAnnoF
            pFeature.Store
        End If
                
        Set pFeature = pEnumFeature.Next
    Loop
    
    pEditor.StopOperation "Set Rotate With Transform"
    
    pEditor.Display.Invalidate Nothing, True, esriAllScreenCaches
End Sub

Public Sub RotateWithTransform_Map()
'   1. Select Map annotation using the Select Elements tool
'   2. Change Const value above to either True or False (True = rotate text when dataframe rotates)
'   3. Run this code
'   4. Save your .mxd to save changes

  Dim pMxDoc As IMxDocument
  Set pMxDoc = ThisDocument
  Dim pGraphicsContSelect As IGraphicsContainerSelect
  If pMxDoc.ActiveView Is pMxDoc.PageLayout Then
    Set pGraphicsContSelect = pMxDoc.PageLayout
  Else
    Set pGraphicsContSelect = pMxDoc.FocusMap
  End If

  Dim pElement As IElement
  Dim Count As Long
  Count = pGraphicsContSelect.ElementSelectionCount - 1
  Dim i As Long
  
  For i = 0 To Count
   Set pElement = pGraphicsContSelect.SelectedElement(i)
    If TypeOf pElement Is ITextElement Then
        Dim pTextElement As ITextElement
        Dim pTextSymbol As ITextSymbol
        Dim pSymbolRotation As ISymbolRotation
        Set pTextElement = pElement
        Set pSymbolRotation = pTextElement.Symbol
        pSymbolRotation.RotateWithTransform = ROTATE_WITH_TRANSFORM
        pTextElement.Symbol = pSymbolRotation
    End If
   Next i

   pMxDoc.ActiveView.Refresh
End Sub
  1. There are two subroutines, the first works for geodatabase annotation, and the other works for map document annotation. Find the routine that fits the situation and follow the directions at the top of the subroutine to run it.

Related Information

Last Published: 8/5/2019

Article ID: 000006191