Add text in paper space

Add text in paper space

Anonymous
Not applicable
2,437 Views
5 Replies
Message 1 of 6

Add text in paper space

Anonymous
Not applicable

I am trying to add a simple line of text to paper space using VBA with a specific insert point.  I'm sure it is a very simple code, but nothing I try works.  

 

Thanks in advance!

0 Likes
Accepted solutions (2)
2,438 Views
5 Replies
Replies (5)
Message 2 of 6

grobnik
Collaborator
Collaborator
Accepted solution

Hi @Anonymous 

the code below it's coming from Autocad Help so nothing of special procedure, probably you didn't insert Set before apply the Addtext function. 

 

 

 

Sub InsertTextPaperSpace()
Dim InsPoint(0 To 2) As Double
Dim TextToInsert As String
Dim TextObj As AcadText
Dim Height As Double

InsPoint(0) = 25
InsPoint(1) = 35
InsPoint(2) = 0
TextToInsert = "TEXT TO INSERT"
Height = 25

Set TextObj = ThisDrawing.PaperSpace.AddText(TextToInsert, InsPoint, Height)
ThisDrawing.Regen acAllViewports
ZoomAll
End Sub

 

 

See picture below for procedure functionality confirmation

grobnik_0-1595146141861.png

Let us know

 

Message 3 of 6

Anonymous
Not applicable

That is exactly what happened.  Thanks so much for your help.  Anyway I can make this text I am inserting a certain color?  It is easy to change manually but would be nice to have it come in the color I want. 

 

0 Likes
Message 4 of 6

Anonymous
Not applicable

That is exactly what happened.  Thanks so much for your help.  Anyway I can make this text I am inserting a certain color?  It is easy to change manually but would be nice to have it come in the color I want. 

0 Likes
Message 5 of 6

grobnik
Collaborator
Collaborator

Hi @Anonymous 

Once you have the text object 

 

TextObj 

 

This will have some properties, look at debug, you can change color, font, and so on, add special char.

If you want to use true color for example it's more or less different see below code:

 

Dim color As AcadAcCmColor
Dim sVer As String = Left(acadDoc.GetVariable("ACADVER"), 2)
Set color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor." & sVer)
'Above automatic Get Cad Version, below manual.
'Set color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.20")
'For Acad2015, use AutoCAD.AcCmColor.20
'For Acad2016/17, use AutoCAD.AcCmColor.21
'For Acad2018, use AutoCAd.AcCmColor.22
'For Acad2019, use AutoCAD.AcCmColor.23
Call color.SetRGB(80, 100, 244) ' Set RGB colors as you want
TextObj.TrueColor = color

 

You will find a lot of literature on forum about text properties.

0 Likes
Message 6 of 6

grobnik
Collaborator
Collaborator
Accepted solution

Hi @Anonymous 

sorry there is a mistake in the code here below the complete code working with color changing too:

Sub InsertTextPaperSpace()
Dim InsPoint(0 To 2) As Double
Dim TextToInsert As String
Dim TextObj As AcadText
Dim Height As Double
Dim color As AcadAcCmColor
Dim sVer As String
sVer = Left(AcadApplication.Version, 2)
Set color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor." & sVer)
'Above automatic Get Cad Version, below manual.
'Set color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.20")
'For Acad2015, use AutoCAD.AcCmColor.20
'For Acad2016/17, use AutoCAD.AcCmColor.21
'For Acad2018, use AutoCAd.AcCmColor.22
'For Acad2019, use AutoCAD.AcCmColor.23
Call color.SetRGB(88, 99, 115) ' Set RGB colors as you want
InsPoint(0) = 25
InsPoint(1) = 35
InsPoint(2) = 0
TextToInsert = "TEXT TO INSERT"
Height = 25

Set TextObj = ThisDrawing.PaperSpace.AddText(TextToInsert, InsPoint, Height)
TextObj.TrueColor = color

ThisDrawing.Regen acAllViewports
ZoomAll
End Sub