HOW TO

Center a view's display on user-defined coordinates

Last Published: April 25, 2020

Summary

The Avenue code below allows you to define a set of coordinates to center a view's display.

Procedure



  1. Open a new script window.

    A. Activate the Project window.
    B. Click the Scripts icon.
    C. Click New.

  2. Copy the code into the new script window.

    Code:
    ' SetViewDisplayCenter

    ' This script pans the view display extent to the center of the
    ' specified x,y coordinate while retaining the
    ' view's original extent.
    ' The view must be the active document when running the script.

    theView = av.GetActiveDoc
    theDisplay=theView.GetDisplay

    'Get Visible Extent
    theExtent=theDisplay.ReturnVisExtent
    theSize=theExtent.ReturnSize
    theSizeX=theSize.GetX
    theSizeY=theSize.GetY

    'Calculate the x and y sizes divided by 2
    thesizeX2=theSizeX/2
    theSizeY2=theSizeY/2

    'Set Message Box Input
    labels={"x","y"}
    defaults={"0","0"}

    'Enter new Coos
    userXY=MsgBox.MultiInput("Enter the new coos","View Move",labels,defaults)

    'Get and convert Coos to numbers
    userX=userXY.Get(0).AsNumber
    userY=userXY.Get(1).AsNumber

    'Calculate the new rectangle's Size
    userx2=userX-theSizeX2
    userY2=userY-theSizeY2
    userx22=userX+theSizeX2
    userY22=userY+theSizeY2

    'Make the Rectangle
    theNewExtent=Rect.MakeXY(userx2,usery2,userx22,usery22)

    'Set the new extent
    theDisplay.SetExtent(theNewExtent)

  3. Compile the script by clicking the compile button.
    [O-Image] Script compile button
  4. Run the script by clicking the run button.
    [O-Image] Run compiled script button

Article ID:000005055

Software:
  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic