18, Feb, 2019

Insert a text in an AutoCAD Drawing using VBA

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>