HOW TO

Set a reference scale for a text element on a map with ArcObjects

Last Published: April 25, 2020

Summary

Note:
This article pertains to ArcGIS versions 9.x only. 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 set a reference scale for text elements on a map with ArcObjects.

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, while the Customize dialog box is open and select View Source.
  2. Copy this code into the UIButtonControl's click event.
Sub TextElemRefScale()
    Dim pDoc As IMxDocument
    Dim pContainer As IGraphicsContainer
    Dim pElement As IElement
    Dim pTextElement As ITextElement
    Dim pActiveView As IActiveView
    
    Set pDoc = ThisDocument
    Set pActiveView = pDoc.ActiveView
    Set pContainer = pActiveView
    
    'Loop through the graphics container
    'and find text element
    pContainer.Reset
    Set pElement = pContainer.Next
    While Not pElement Is Nothing
        'Get the specific text element
        If TypeOf pElement Is ITextElement Then
           Set pTextElement = pElement
           If pTextElement.Text = "oregon" Then  'specify the text of your text element
                Dim pElemProp As IElementProperties3
                Set pElemProp = pTextElement
                pElemProp.ReferenceScale = 15000000  'change this to the desired reference scale
            End If
        End If
        Set pElement = pContainer.Next
    Wend
    
    'refresh only the graphics, which includes text elements
    pDoc.ActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing
End Sub

Article ID:000009079

Software:
  • ArcMap 9 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic