Align Line Text
 
 
 

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.

Realign text

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 object
	textString = "Hello, World."
	insertionPoint(0) = 3
	insertionPoint(1) = 3
	insertionPoint(2) = 0
	height = 0.5


	' Create the Text object in model space
	Set textObj = ThisDrawing.ModelSpace. _
					AddText(textString, insertionPoint, height)


	' Create a point over the text alignment point,
	' so we can better visualize the alignment process
	Dim pointObj As AcadPoint
	Dim alignmentPoint(0 To 2) As Double
	alignmentPoint(0) = 3
	alignmentPoint(1) = 3
	alignmentPoint(2) = 0
	Set pointObj = ThisDrawing.ModelSpace. _
					AddPoint(alignmentPoint)
	pointObj.Color = acRed


	' Set the point style to crosshair
	ThisDrawing.SetVariable "PDMODE", 2


   ' Align the text to the Left
	textObj.Alignment = acAlignmentLeft
	ThisDrawing.Regen acActiveViewport
	MsgBox "The Text object is now aligned left"


	' Align the text to the Center
	textObj.Alignment = acAlignmentCenter


	' Align the text to the point (necessary for
	' all but left aligned text.)
	textObj.TextAlignmentPoint = alignmentPoint


	ThisDrawing.Regen acActiveViewport
	MsgBox "The Text object is now centered"


	' Align the text to the Right
	textObj.Alignment = acAlignmentRight
	ThisDrawing.Regen acActiveViewport
	MsgBox "The Text object is now aligned right"


End Sub