Alignment Property (ActiveX)

Specifies both the vertical and horizontal alignments for the attribute, attribute reference, or text.

Supported platforms: Windows only

Signature

VBA:

object.Alignment
object

Type: Attribute, AttributeRef, Text

The objects this property applies to.

Property Value

Read-only: No

Type: acAlignment enum

Remarks

Text aligned to acAlignmentLeft uses the InsertionPoint property to position the text.

Text aligned to acAlignmentAligned or acAlignmentFit uses both the InsertionPoint and TextAlignmentPoint properties to position the text.

Text aligned to any other position uses the TextAlignmentPoint property to position the text.



Examples

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

Visual LISP:

(vl-load-com)
(defun c:Example_Alignment()
   ;; This example creates a text object in model space and
   ;; demonstrates setting the alignment of the new text string
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
    
    ;; Define the new Text object
    (setq insertionPoint (vlax-3d-point 3 3 0)  
          alignmentPoint (vlax-3d-point 3 3 0)  
          textString "Hello, World."
          height 0.5)
    
    ;; Create the Text object in model space
    (setq modelSpace (vla-get-ModelSpace doc))
    (setq textObj (vla-AddText modelSpace textString insertionPoint height))
    
    (setq oldPDMODE (vlax-variant-value (vla-GetVariable doc "PDMODE")))   ;; Record existing point style
    
    ;; Create a crosshair over the text alignment point
    ;; to better visualize the alignment process
    (setq pointObj (vla-AddPoint modelSpace alignmentPoint))
    
    (vla-SetVariable doc "PDMODE" 2)             ;; Set point style to crosshair
        
    (vla-ZoomAll acadObj)
    
    ;; 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
    (vla-put-Alignment textObj 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
    (vla-put-TextAlignmentPoint textObj alignmentPoint)
    (vla-Regen doc acActiveViewport)
    (alert "The Text object is now aligned to the right of the alignment point.")
    
    ;; Center the text to the alignment point
    (vla-put-Alignment textObj acAlignmentCenter)
    (vla-Regen doc acActiveViewport)
    (alert "The Text object is now centered to the alignment point.")
    
    ;; Reset point style
    (vla-SetVariable doc "PDMODE" oldPDMODE)
)