HOW TO

Convert text from a view into a .dbf with coordinates

Last Published: April 25, 2020

Summary

The script below is designed to take the text from a view and place it into a table that can be used as an event theme. It also allows for the text to be added into other applications, such as ArcInfo and various CAD applications.

Procedure



  1. Open a new script window.

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

  2. Copy the following code into the new window:

    Code:
    '-- This script will take all of the GraphicText
    '-- objects in a view, and add the coordinates of
    '-- their origins and text to a table.

    '-- Get the View and the Project
    theView = av.GetActiveDoc
    theProject = av.GetProject

    '-- Get all of the GraphicText objects in the view
    theGtl = theView.GetGraphics.FindAllByClass(GraphicText)

    '-- Ask the user for a name and location for the new table
    def = av.GetProject.MakeFileName("label", "dbf")
    theName = FileDialog.Put(def, "*.dbf", "Select file location")

    '-- Create the table and the fields
    theNewVTab = VTab.MakeNew(theName,dbase)
    xfield = Field.Make("xcoord",#FIELD_FLOAT, 12,6)
    yfield = Field.Make("ycoord",#FIELD_FLOAT, 12,6)
    idfield = field.make("id", #FIELD_SHORT, 5,0)
    textfield = Field.Make("text", #FIELD_CHAR, 30,0)
    theNewVTab.AddFields({xfield, yfield, idfield, textfield})

    '-- Add the graphic information to the table
    For Each gt in theGtl
    recnum = theNewVtab.AddRecord
    theNewVTab.SetValue(xfield, recnum, gt.GetOrigin.GetX)
    theNewVTab.SetValue(yfield, recnum, gt.GetOrigin.GetY)
    theNewVTab.SetValue(idfield, recnum, (recnum+1))
    theNewVTab.SetValue(textfield, recnum, gt.GetText)
    end

    '-- Create the table doc and add it to the project
    theNewTable = Table.Make(theNewVTab)
    theNewTable.SetName(theNewVTab.GetName)
    theProject.AddDoc(theNewTable)
    theNewTable.GetWin.Open
    theNewVTab.SetEditable(FALSE)

  3. Click the Compile button.
    [O-Image] Script compile button
  4. Position the view and the script window so that both are visible.
  5. Make the view active.
  6. Click the script window.
  7. Click the Run button.
    [O-Image] Run compiled script button

Article ID:000004195

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