English

How To: Use TextPositioner to place text along a line feature

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