Create Multiline Text

AutoCAD ActiveX

 
Create Multiline Text
 
 
 

You can create a multiline text object (MText object) by using the AddMText method. This method requires three values as input: the text string, the insertion point in the drawing to place the text, and the width of the text bounding box.

The text string is the actual text to be displayed. Unicode, control code, and special characters are accepted. The insertion point is a variant array containing three doubles representing the 3D WCS coordinate in the drawing to place the text. The width of the text is a positive number representing the width of the bounding box for the text. Width is measured in the current units.

After the MText object is created, you can apply the text height, justification, rotation angle, and style to the MText object, or apply character formatting to selected characters.

Refer to the entry on MText in the ActiveX and VBA Reference for a list of methods and properties that apply to the MText object.

To Create Multiline Text

The following code creates an MText object in model space, at the coordinate (2, 2, 0).

Sub Ch4_CreateMText()
    Dim mtextObj As AcadMText
    Dim insertPoint(0 To 2) As Double
    Dim width As Double
    Dim textString As String
      
    insertPoint(0) = 2
    insertPoint(1) = 2
    insertPoint(2) = 0
    width = 4
    textString = "This is a text string for the mtext object."
      
    ' Create a text Object in model space
    Set mtextObj = ThisDrawing.ModelSpace. _
 AddMText(insertPoint, width, textString)
    ZoomAll
End Sub