Insert a text in an AutoCAD Drawing using VBA

Submitted by CAAadmin on Mon, 08/15/2016 - 05:49

Please refer our previous articles related to autocad to understand macro/vba concepts

Steps :

1. Create a form and insert a button

2. Double click on the button then add following codes


Dim textObj2 As AcadText

Dim insertionPoint2(0 To 2) As Double

Dim textString2 As String

' Define the text object

textString2 = "YOUR TEXT HERE "

insertionPoint2(0) = 10: insertionPoint2(1) = 10: insertionPoint2(2) = 0

Height = 4

' Create the text object in model space

Set textObj2 = ThisDrawing.ModelSpace.AddText(textString2, insertionPoint2, Height)


3. Add your text above "YOUR TEXT HERE"

4. Run the program

you may use another text box to add the text while running the program, in that case textString2  = TextBox1.text