Alignment Example

Using Programming Languages other than VBA

Sub Example_Alignment()
   ' This example creates a text object in model space and
   ' demonstrates setting the alignment of the new text string

	Dim textObj As AcadText
	Dim textString As String
	Dim insertionPoint(0 To 2) As Double, alignmentPoint(0 To 2) As Double
	Dim height As Double
	Dim oldPDMODE As Integer
	Dim pointObj As AcadPoint

	' Define the new Text object
	textString = "Hello, World."
	insertionPoint(0) = 3: insertionPoint(1) = 3: insertionPoint(2) = 0
	alignmentPoint(0) = 3: alignmentPoint(1) = 3: alignmentPoint(2) = 0
	height = 0.5

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

	oldPDMODE = ThisDrawing.GetVariable("PDMODE")   ' Record existing point style

	' Create a crosshair over the text alignment point
	' to better visualize the alignment process
	Set pointObj = ThisDrawing.ModelSpace.AddPoint(alignmentPoint)

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

	' Set the text alignment to a value other than acAlignmentLeft, which is the default.
	' Create a point that will act as an alignment reference point
	textObj.Alignment = acAlignmentRight

	' Create the text alignment reference point and the text will automatically
	' align to the right of this point, because the text
	' alignment was set to acAlignmentRight
	textObj.TextAlignmentPoint = alignmentPoint
	ThisDrawing.Regen acActiveViewport
	MsgBox "The Text object is now aligned to the right of the alignment point"

	' Center the text to the alignment point
	textObj.Alignment = acAlignmentCenter
	ThisDrawing.Regen acActiveViewport
	MsgBox "The Text object is now centered to the alignment point"

	' Reset point style
	ThisDrawing.SetVariable "PDMODE", oldPDMODE
End Sub

 

   Comments?