HOW TO
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.
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
Code:
Write #FileNum, pFeat.OID, "A" & pFeat.OID, sText, pPolyline.ToPoint.X, pPolyline.ToPoint.Y
Article ID: 000010373
Get help from ArcGIS experts
Download the Esri Support App