Visual Basic Customization

Visual Basic Customization

Reply
Valued Contributor
Montana.Fox
Posts: 56
Registered: ‎02-13-2006
Message 1 of 8 (179 Views)

Status Bar to show active document filename

179 Views, 7 Replies
08-24-2007 09:43 AM
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.
Contributor
har!s
Posts: 22
Registered: ‎03-03-2007
Message 2 of 8 (179 Views)

Re: Status Bar to show active document filename

08-24-2007 10:30 PM in reply to: Montana.Fox
Call the sub from Doc_Activate event.

Public WithEvents Doc As AcadDocument
Private Sub Doc_Activate()
StatusChg
End Sub
Valued Contributor
Montana.Fox
Posts: 56
Registered: ‎02-13-2006
Message 3 of 8 (179 Views)

Re: Status Bar to show active document filename

08-27-2007 09:09 AM 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...
Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 4 of 8 (179 Views)

Re: Status Bar to show active document filename

08-27-2007 03:21 PM in reply to: Montana.Fox
Add the following to ThisDrawing module:

Private Sub AcadDocument_Activate()
StatusChg
End Sub
Valued Contributor
Montana.Fox
Posts: 56
Registered: ‎02-13-2006
Message 5 of 8 (179 Views)

Re: Status Bar to show active document filename

08-27-2007 03:41 PM 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.
Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 6 of 8 (179 Views)

Re: Status Bar to show active document filename

08-27-2007 03:48 PM 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
Valued Contributor
Montana.Fox
Posts: 56
Registered: ‎02-13-2006
Message 7 of 8 (179 Views)

Re: Status Bar to show active document filename

08-27-2007 03:55 PM 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.
Valued Contributor
Montana.Fox
Posts: 56
Registered: ‎02-13-2006
Message 8 of 8 (179 Views)

Re: Status Bar to show active document filename

08-28-2007 08:04 AM 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.
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.