Align Line Text
From AutoCAD ActiveX
You can justify line text horizontally and vertically. Left alignment is the default. To set the horizontal and vertical alignment options, use the Alignment property.
This example creates a Text object and a Point object. The Point object is set to the text alignment point, and is changed to a red crosshair so that it is visible. The text alignment is changed and a message box is displayed so that the macro execution is halted. This allows you to see the impact of changing the text alignment.
Sub Ch4_TextAlignment()
Dim textObj As AcadText
Dim textString As String
Dim insertionPoint(0 To 2) As Double
Dim height As Double
' Define the new Text objecttextString = "Hello, World."insertionPoint(0) = 3insertionPoint(1) = 3insertionPoint(2) = 0height = 0.5' Create the Text object in model spaceSet textObj = ThisDrawing.ModelSpace. _AddText(textString, insertionPoint, height)' Create a point over the text alignment point,' so we can better visualize the alignment processDim pointObj As AcadPointDim alignmentPoint(0 To 2) As DoublealignmentPoint(0) = 3alignmentPoint(1) = 3alignmentPoint(2) = 0Set pointObj = ThisDrawing.ModelSpace. _AddPoint(alignmentPoint)pointObj.Color = acRed' Set the point style to crosshairThisDrawing.SetVariable "PDMODE", 2' Align the text to the LefttextObj.Alignment = acAlignmentLeftThisDrawing.Regen acActiveViewportMsgBox "The Text object is now aligned left"' Align the text to the CentertextObj.Alignment = acAlignmentCenter' Align the text to the point (necessary for' all but left aligned text.)textObj.TextAlignmentPoint = alignmentPointThisDrawing.Regen acActiveViewportMsgBox "The Text object is now centered"' Align the text to the RighttextObj.Alignment = acAlignmentRightThisDrawing.Regen acActiveViewportMsgBox "The Text object is now aligned right"End Sub