Add file name as Mtext

Add file name as Mtext

abbas.baghernezhad
Enthusiast Enthusiast
630 Views
4 Replies
Message 1 of 5

Add file name as Mtext

abbas.baghernezhad
Enthusiast
Enthusiast

Hi 

I want to add file name (or maybe some other information) to my model space like somthing that command "field" does. here is code , it works except the most important thing! How can i access my file name (info variable)?

Sub fn()
Dim pt(0 To 2) As Double
Dim w As Double
Dim text As AcadMText
Dim ent As AcadEntity
Dim info As String

pt(0) = 10: pt(1) = 0: pt(2) = 0
Width = 10
info=?

Set text = ThisDrawing.ModelSpace.AddMText(pt, Width, info)
For Each ent In ThisDrawing.ModelSpace
 If TypeOf ent Is AcadMText Then
Debug.Print ent.TextString
End If
Next

End Sub

 

0 Likes
Accepted solutions (1)
631 Views
4 Replies
Replies (4)
Message 2 of 5

norman.yuan
Mentor
Mentor
Accepted solution

Try this:

 

Option Explicit

Sub fn()
    Dim pt(0 To 2) As Double
    Dim w As Double
    Dim text As AcadMText
    Dim ent As AcadEntity
    Dim info As String
    
    pt(0) = 10: pt(1) = 0: pt(2) = 0
    w = 10
    info = "%<\AcVar Filename \f ""%fn7"">%"
    
    Set text = ThisDrawing.ModelSpace.AddMText(pt, w, info)
    text.Update

End Sub

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 5

abbas.baghernezhad
Enthusiast
Enthusiast

I did try that. But I was getting syntax error... 

some charachter must have been missing.

Thank You.

0 Likes
Message 4 of 5

Ed__Jobe
Mentor
Mentor

A syntax error means that you didn't follow the code language properly. When you get that error, it will highlight the problem code. What line got the error?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 5

abbas.baghernezhad
Enthusiast
Enthusiast

 I mistyped some charachters while copy-pasting. Problem is solved .Thank You. 

0 Likes