HOW TO

Use TextPositioner to place text along a line feature

Last Published: April 25, 2020

Summary

You can use the TextPositioner Avenue class to place text along a line. The script below demonstrates how to do this.

Procedure



  1. Open a new script window.

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

  2. Copy and paste the following script into the new script window:

    Code:
    '-- Open the view with the theme you wish to label.
    '-- Promote the line theme you wish to label to the
    '-- top of the Table of Contents; then run the script.

    '-- Edit the following line with the name of your view.
    theView = av.GetProject.FindDoc("View1")
    thePrj = theView.GetProjection
    theFTab = theView.GetThemes.Get(0).GetFTab
    shapeField = theFTab.FindField("Shape")

    '-- Edit the following line with the name of the field you will use to label with.
    textfield = theFTab.FindField("text")
    thePLine = theFTab.GetShapeClass.MakeNull

    for each rec in theFTab
    theFTab.QueryShape(rec, thePrj, thePLine)
    theText = theFTab.ReturnValueString(textField, rec)
    gt = GraphicText.Make(theText, 0@0)
    gt.SetDisplay(theView.GetDisplay)

    tp = TextPositioner.Make(PolyLine)
    tp.SetHAlign(#TEXTPOSITIONER_HALIGN_CENTER)
    tp.SetVAlign(#TEXTPOSITIONER_VALIGN_ON)
    tp.Calculate(thePLine, gt.GetExtent, 1, nil)

    gt.SetOrigin(tp.GetOrigin)
    gt.SetAngle(tp.GetAngle)

    theView.GetGraphics.Add(gt)
    end

  3. Compile and run the script.

    A. Click the Compile button.
    [O-Image] Script compile button

    B. Click the Run button.
    [O-Image] Run compiled script button

Article ID:000003929

Software:
  • Legacy Products

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options