English

How To: Create a point feature in a specified corner of an annotation feature class in relation to text rotation

Summary

Instructions provided describe how to create a new point feature in a specific corner of each annotation feature of an annotation feature class.

The point feature class is in the desired corner (lower-left or lower-right) of the text, no matter the rotation of the text. For instance, if the code is set to lower-left, and the text is rotated so it reads vertically, bottom to top, the point would be placed in the geographic lower right of the text envelope.
[O-Image] Results

Procedure

The code block is default to the lower-left corner of the text string. See the note below the main code block for instructions to change the corner to the lower-right.

  1. Open Arcmap, and add an annotation feature class.
  2. Open Windows Explorer, and navigate to the C: drive. Create a new folder in the C: drive called 'Test' without quotes. Close Windows Explorer.
  3. In ArcMap, click Tools > Macros > Visual Basic Editor.
  4. In the Table of Contents in Visual Basic Editor, click the plus sign to expand Project, and expand the plus next to ArcMap Objects. Double-click on ThisDocument.
    [O-Image] ThisDocument
  5. Copy and paste the following code into the ThisDocument code box. It is not necessary to click save:

    Code:
    Public Sub GetLabel()

    'Create csv file and write values to it
    'The folder named "Test" must exist on the "Drive C"
    Dim FileNum As Integer
    If Dir("C:\Test\coord.csv") <> "" Then
    ' deletes the file if it exists
    Kill "C:\Test\coord.csv"
    End If
    FileNum = FreeFile

    Open "C:\Test\coord.csv" For Output As #FileNum
    Write #FileNum, "Object_ID", "Anno_ID", "Text_String", "Point_X", "Point_Y"

    Dim pMxDoc As IMxDocument
    Dim pMap As IMap
    Dim pFeat As IFeature
    Dim pEnumFeat As IEnumFeature
    Dim pEnumFeatSetup As IEnumFeatureSetup

    Set pMxDoc = ThisDocument
    Set pMap = pMxDoc.FocusMap
    Set pEnumFeat = pMap.FeatureSelection 'select some annotation
    Set pEnumFeatSetup = pEnumFeat 'QI
    pEnumFeatSetup.AllFields = True
    Set pFeat = pEnumFeat.Next

    Dim pAnnoFeature As IAnnotationFeature
    Dim pPolyline As IPolyline
    Dim sText As String
    Dim pElement As IElement
    Dim pTextElement As ITextElement
    Do While Not pFeat Is Nothing
    If (TypeOf pFeat Is IAnnotationFeature) Then
    Set pAnnoFeature = pFeat
    Set pTextElement = pAnnoFeature.Annotation
    Set pElement = pTextElement

    If (Not pTextElement Is Nothing) Then sText = pTextElement.Text
    Dim pSegmentCollection As ISegmentCollection
    Dim pSegment As ISegment
    Set pPolyline = pElement.Geometry
    Set pSegmentCollection = pPolyline

    Write #FileNum, pFeat.OID, "A" & pFeat.OID, sText, pPolyline.FromPoint.X, pPolyline.FromPoint.Y

    End If
    Set pFeat = pEnumFeat.Next
    Loop

    Close #FileNum

    MsgBox "Coordinate File generated successfully"
    End Sub


    Note:
    In order to change the corner from the lower-left to lower-right, replace the following line of code:

    Code:
    Write #FileNum, pFeat.OID, "A" & pFeat.OID, sText, pPolyline.FromPoint.X, pPolyline.FromPoint.Y


    With this line:

    Code:
    Write #FileNum, pFeat.OID, "A" & pFeat.OID, sText, pPolyline.ToPoint.X, pPolyline.ToPoint.Y


  6. Close the Visual Basic Editor. Return to ArcMap.
  7. In the Table of Contents in ArcMap, right-click the annotation feature class > Selection > Select All.
  8. Click Tools > Macros > Macros. Select the Macro called 'ThisDocument.GetLabel' and click Run.
  9. After the 'Coordinate File generated successfully' message, click Add Data. Navigate to the C: drive > Test folder. Add the .csv file that was created called 'coords.csv'.
  10. In the Table of Contents, right-click the .csv > Display XY Data. Select the Point_X field for X field and Point_Y field for Y field. Select the same coordinate system as the annotation feature class. Click OK.
  11. After the points plot, right-click the point event layer in the Table of Contents, click Data > Export Data, and export the event layer to a permanent feature class.