VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Status Bar to show active document filename

7 REPLIES 7
Reply
Message 1 of 8
Montana.Fox
347 Views, 7 Replies

Status Bar to show active document filename

I am trying to make the status bar in AutoCAD show the name of the active document. For example, if I have a file whose fullname is something like "C:/MyFiles/AutoCAD Files/Drawing123.dwg", I want the status bar to show "Drawing123.dwg". I have managed to make that happen. However, I also need for this to update when I open another file (such as DrawingABC.dwg). Is there a way I can make the status bar update every time the active document is changed? Right now, if I start with Drawing123 open, and then open or switch to DrawingABC, the status bar still displays "Drawing123".

Here's what I've got so far...
-------------------------------------------------------------------

Public Function StatusChg()
nameshort = Application.ActiveDocument.Name
ThisDrawing.SetVariable "MODEMACRO", nameshort
End Function
-------------------------------------------------------------------

Basically, I just need to figure out how to call the StatusChg function whenever the ActiveDocument is changed.

Thanks in advance.
7 REPLIES 7
Message 2 of 8
har!s
in reply to: Montana.Fox

Call the sub from Doc_Activate event.

Public WithEvents Doc As AcadDocument
Private Sub Doc_Activate()
StatusChg
End Sub
Message 3 of 8
Montana.Fox
in reply to: Montana.Fox

I'm having a hard time getting that to work. I'm not as familiar with Class Modules as I am regular Modules, but apparently, the WithEvents will only work in a Class module (according to the Help files). However, I have placed all of the code you provided in that Class Module, and when I try to run Doc_Activate it tells me that the Sub or Function is not defined. Should I be placing the actual Sub in a regular Module? I tried doing that, but had to make it Public instead of Private, and it did not have any effect when I activated another document. Not sure what I'm missing...
Message 4 of 8
NathTay
in reply to: Montana.Fox

Add the following to ThisDrawing module:

Private Sub AcadDocument_Activate()
StatusChg
End Sub
Message 5 of 8
Montana.Fox
in reply to: Montana.Fox

Ok. I tried both of these methods, and neither of them seems to be making the status change when a different drawing is activated. I apologize if I'm just ignorant, but I don't understand how the Private Subs you have both kindly suggested are to be initiated. Are they supposed to run automatically whenever the active document is changed? Because that's not happening, but it is what I want to happen.
Message 6 of 8
NathTay
in reply to: Montana.Fox

The following works for me when inserted in ThisDrawing module.

Private Sub AcadDocument_Activate()
Dim nameshort As String
nameshort = Application.ActiveDocument.Name
ThisDrawing.SetVariable "MODEMACRO", nameshort
End Sub
Message 7 of 8
Montana.Fox
in reply to: Montana.Fox

Hm. Well, that's not working for me, but thanks for your help. I'll keep on truckin' and see if I can't figure out why that's not doing the trick for me.

By the way, I don't know that it makes a difference, but I'm in ADT 2007.
Message 8 of 8
Montana.Fox
in reply to: Montana.Fox

Aha! At last, I have figured out why it wasn't working for me. I wasn't taking you literally enough. I am novice enough to not realize that ThisDrawing IS a module I can put code into. I had been right-clicking on ThisDrawing and creating a module, where I would place the code. This is where I was going wrong. It finally occurred to me to put the sub directly into the ThisDrawing module (which I know is exactly what you'd said to do - I just was ignorant).

This works exactly the way I needed it to after all. Thanks so much for your help, and for putting up with my novice.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost