English

How To: Automatically synchronize display units to match map units

Summary

When you change from one projected coordinate system to another, the display units automatically change to match the map units. However, when you change from a projected coordinate system to a geographic coordinate system, the display units remain in their previous linear units. The following sample script synchronizes the map units and display units whenever you change the data frame's coordinate system.

Procedure

  1. Start ArcMap.
  2. Click Tools > Macros > Visual Basic Editor.
  3. Double-click Normal (Normal.mxt) > ArcMap Objects > This document in the VBA Project window.
  4. Copy the following code into the new window.

    Code:
    Private WithEvents MapActiveViewEvents As Map

    Private Function MxDocument_NewDocument() As Boolean
    EventListener
    End Function

    Private Function MxDocument_OpenDocument() As Boolean
    EventListener
    End Function

    Private Sub EventListener()
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    Set MapActiveViewEvents = pMxDoc.FocusMap
    End Sub

    Private Sub MapActiveViewEvents_SpatialReferenceChanged()
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument

    Dim pMap As IMap
    Set pMap = pMxDoc.FocusMap

    '-- Set display units to be the same as map units
    pMap.DistanceUnits = pMap.MapUnits
    End Sub

  5. Click File > Save normal.mxt.
  6. Exit the Visual Basics Editor.

    Note:
    The above code has been associated with the normal template and responds to the SpatialReferenceChanged event. It will be initialized the next time you start a new ArcMap document or load a pre-existing document.