To continue the prior thread
Here is the same method for plain text:
Sub AlignText()
Dim sset As AcadSelectionSet
Dim dxfCode, dxfValue
Dim ftype(0) As Integer
Dim fdata(0) As Variant
ftype(0) = 0: fdata(0) = "LINE"
dxfCode = ftype: dxfValue = fdata
Dim lineObj As Object
Dim oText As AcadText
Dim oEnt As AcadEntity
Dim strText1 As String
Dim strText2 As String
Dim txtPt As Variant
Dim movePt1 As Variant
Dim movePt2 As Variant
Dim dblHgt As Double
Dim dblAng As Double
Dim moveAng As Double
Dim rotAng As Double
Dim PI As Double
PI = Atn(1) * 4
' Define the new Text object
strText1 = "First line"
strText2 = "Second line"
dblHgt = 0.125
With ThisDrawing.SelectionSets
While .Count > 0
.Item(0).Delete
Wend
End With
Set sset = ThisDrawing.SelectionSets.Add("$Lines$")
sset.SelectOnScreen dxfCode, dxfValue
For Each oEnt In sset
' get the line object
Set lineObj = oEnt
txtPt = lineObj.StartPoint
' get line angle
dblAng = lineObj.Angle
' Debug.Print dblAng ' debug only
' recalculate rotation angle
If dblAng >= 0 Then
rotAng = dblAng
End If
If dblAng > PI / 2 Then
rotAng = PI + dblAng
End If
If dblAng >= PI * 1.5 Then
rotAng = dblAng
End If
If dblAng >= PI * 1.5 And dblAng <= PI * 2 _
Or dblAng <= PI / 2 And dblAng >= 0 Then
moveAng = dblAng + PI / 2
Else
moveAng = dblAng - PI / 2
End If
' Debug.Print rotAng ' debug only
' update text object
movePt1 = ThisDrawing.Utility.PolarPoint(txtPt, moveAng, 0.25 * dblHgt) '< --0.25 * dblHgt is text offset change to suit
' Create the Text object in model space
Set oText = ThisDrawing.ModelSpace.AddText(strText1, movePt1, dblHgt)
oText.Alignment = acAlignmentBottomCenter
oText.TextAlignmentPoint = movePt1
oText.Rotation = rotAng
movePt2 = ThisDrawing.Utility.PolarPoint(txtPt, moveAng + PI, 0.25 * dblHgt) '< --0.25 * dblHgt is text offset change to suit
' Create the Text object in model space
Set oText = ThisDrawing.ModelSpace.AddText(strText2, movePt2, dblHgt)
oText.Alignment = acAlignmentTopCenter
oText.TextAlignmentPoint = movePt2
oText.Rotation = rotAng
Next oEnt
End Sub
~'J'~