Help about set text in Autocad VBA

Help about set text in Autocad VBA

Anonymous
Not applicable
3,731 Views
4 Replies
Message 1 of 5

Help about set text in Autocad VBA

Anonymous
Not applicable

With this sub, I create a text in AutoCAD.

 

Sub Ch4_ChangeTextHeight()
Dim textObj As AcadText
Dim textString As String
Dim insertionPoint(0 To 2) As Double
Dim height As Double

textString = "Hello, World."
insertionPoint(0) = 0
insertionPoint(1) = 0
insertionPoint(2) = 0
height = 1

Set textObj = ThisDrawing.ModelSpace. _
AddText(textString, insertionPoint, height)

End Sub

 

But, when I type -vp  and then "1,1,1" to set view in AutoCAD, my view will change, and I can not see my text as before.

Tell me how to set View for this text or something similar 😞


0 Likes
3,732 Views
4 Replies
Replies (4)
Message 2 of 5

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

Sorry, we (at lest I) need some details

 

>> when I type -vp  and then "1,1,1" to set view in AutoCAD, my view will change

that's normal, that the viewchanges with command _VPOINT ... did you estimate anything else then a 3D-rotated view now? If so, what should the display look like?

 

>> [...] and I can not see my text as before

Well, you see the text now from a different angle in XY and from a different elevation. I see not any difference to a text that is created with TEXT-command (without VBA) and that produced by your code.

Or what is it that makes you thinking that something went wrong? Explain it, maybe screenshots can help or drawings (one what happend and another DWG what you estimate instead).

 

If you are wondering that the text-object is not vertical oriented after you changed your viewpoint then .... that is normal. A text-object "lays" in the XY-plane of the UCS that was active during creation of the text.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 5

Anonymous
Not applicable

thank you for so quick reply

sorry for my description

 

First. This is when i type a text first.JPG

 

then I change my view 

 

second.JPG

 

And how I can change the view of this text or st similar  as below

 

third.JPG

 

 

 

 

0 Likes
Message 4 of 5

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

if you take a paper with some characters on it and place it on the floor. Then first look to the text from vertical above the paper, next go a few steps away and look then to the characters ... did they follow you? NO 😉

And that's the same like any geometry in AutoCAD does, if you place a quader in your scene and you change then your point of view, nothing follows with you, but you see the quader-object from another side and another height. A text-object is nothing else than a simple geometry object, it stays where you placed it as long as you don't modify the geometry.

 

To your screen 3, this is just temporary for editing the text-content. So during modification AutoCAD transforms the text-content parallel to screenview and when you finished the modification the temporary display is off, the text is back to it's creation plane.

 

But at least, there is no difference between a text created manually with AutoCAD-commands or with VBA.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 5 of 5

Hallex
Advisor
Advisor

Set ISO View you  need , draw some text, then

you can play around this quick demo:

 

    Public Sub SetTextPlanar()
    Dim oText As AcadText
    Dim pickPt As Variant
    Dim oEnt As AcadEntity
    Dim textPt As Variant
    Dim vdir As Variant
    Dim align As Integer
    Dim txtAlign As Variant
    
    vdir = ThisDrawing.GetVariable("viewdir")

    ThisDrawing.Utility.GetEntity oEnt, pickPt, vbCr & "Select text: "
    
    If TypeOf oEnt Is AcadText Then
    
    Set oText = oEnt
    
    textPt = oText.InsertionPoint
    
    align = oText.Alignment
    
    txtAlign = oText.TextAlignmentPoint
    
    oText.Normal = vdir
    
    If align = 0 Then
    
    oText.InsertionPoint = textPt
    
    txtAlign = oText.TextAlignmentPoint
    
    ElseIf align = 5 Or align = 3 Then
    
    oText.Alignment = align
    
    oText.TextAlignmentPoint = txtAlign
    
    oText.InsertionPoint = textPt
    
    Else
    
    oText.TextAlignmentPoint = txtAlign

    End If

    End If
    
    ThisDrawing.Regen acActiveViewport

    
End Sub

 

 

~'J'~

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes