HOW TO

Center text around a user-defined point

Last Published: April 26, 2020

Summary

The following script provides one way to center text around a user-defined point.

Procedure

This script uses a hard-coded text string. You need to modify this string to suit your needs.
  1. Open a new script window.
    1. Activate the Project window.
    2. Click the Scripts icon.
    3. Click New.
  2. Copy the following code into the new window:
    Code:
    '-- Headline: Centers GraphicText around a point
    '-- Description: The script will center a GraphicText object
    '-- over a user specified point. Attach this script to the
    '-- apply event of a Tool Button. 
    '-- If the view you are working in is not named View1, 
    '-- you will have to edit the script to use the correct name.
    
    aView=av.Getproject.Finddoc("View1")
    aDisp=aView.GetDisplay 
    aGlist=aView.GetGraphics 
    
    '-- The point is returned when the user clicks the view
    aPnt=aDisp.ReturnUserPoint 
    
    '-- Change "Sample Test String" in the next line to what
    '-- you would like to use. 
    aGtext=GraphicText.Make("Sample Test String", 0@0) 
    
    '-- Create the TextPositioner Object and set the origin 
    '-- of the GraphicText to it.
    tp=PointTextPositioner.Make 
    tp.SetHAlign(#TEXTPOSITIONER_HALIGN_CENTER) 
    tp.SetVAlign(#TEXTPOSITIONER_VALIGN_ON) 
    aGlist.Add(aGtext) 
    tp.Calculate(aPnt, aGtext.GetExtent, 8, nil) 
    aGtext.SetOrigin(tp.GetOrigin) 
    
    '-- Add the user defined point as a GraphicShape
    aGs=GraphicShape.Make(aPnt) 
    aGlist.Add(aGs) 
    aView.Invalidate
    
  3. Attach the script to the Apply event of a new tool.
    1. Compile the script.
    2. Make the Project window active.
    3. Select Customize from the Project menu.
    4. Set the Type dropdown to View on the Customize dialog box.
    5. Set the Category dropdown to Tools.
    6. Click Tool.
    7. Double-click the Apply property at the bottom of the Customize dialog box.
    8. Type the name of the script in the Script Manager and click Select.
    9. Close the Customize dialog box.
    Note:
    For more information, refer to the ArcView Help topic "Customize (dialog box)."
  4. Use the tool to add the point and text graphics to the active view.

Article ID:000003716

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