TheSwamp
Code Red => VB(A) => Topic started by: ML on January 11, 2008, 12:36:03 PM
-
Has anyone ever programmed a system variable change event?
I seem to be missing something
I am trying to do something if ACAD successfully recognizes that I have changed my workspace.
Any ideas?
Thanks!
Mark
Private Sub ACADApp_SysVarChanged(ByVal SysvarName As String, ByVal newVal As Variant)
Select Case SysvarName
Case Is = "wscurrent"
Case newVal = "Test"
MsgBox "Anything?"
End Select
End Sub
-
SysvarName will always be in CAPS so your test fails. Also, you cannot set the newValue, this is a value passed TO the handler telling you what the value has been changed to.
Try this (not tested as I'm not running 2008 at the moment)
Private Sub ACADApp_SysVarChanged(ByVal SysvarName As String, ByVal newVal As Variant)
Select Case SysvarName
Case Is = "WSCURRENT"
Msgbox "New value for WSCURRENT is " & newVal
End Select
End Sub
-
Hey Jeff
That is not doing it either. hummmmm
Any other ideas?
THanks!
Mark
-
Mark,
I had to shutdown Acad and restart it to get the Event to start working. Just tested the code I posted in C3D2008 and this is the result:
-
Ahhhhhh
Good point or just run the startup macro again that is accessing the acad object.
Yes sir! That did it!
Cool! Thanks Jeff!
Mark
-
Jeff
Here is a fun one for you that I wrote a few years back
A lot of fun! LOL
Put this on your Begin Commnad Event
Mark
Select Case CommandName
Case Is = "LINE"
MsgBox "We apologize for the inconvenience but AutoCAD has temporarily ran out of lines" & vbCrLf & _
"Please try again", vbCritical
SendKeys "{ESC}"
End Select
-
I actually use that to prevent my users from using BEdit
-
You mean The
Command Change Event?
You don't use the out of lines code, do yeah? LOL
That code is great is someone screws with you.
Well, I told you the story.
I got that SOB! LOL
Mark
-
Actually I am still having some trouble here;
I (we) got the the msgbox to return the workspace on the system Variable change but
I am now trying to get it to recognize a specifically named Workspace
Not sure what I am missing hmmmmmmm
Mark
-
Post what you have so far
-
Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
Dim strUser As String
Select Case UCase(CommandName)
Case Is = "BEDIT"
strUser = UCase(Environ("USERNAME"))
Select Case strUser
Case "UA02038"
Case "UA03347"
Case Else
MsgBox "B-Edit has been removed," & vbCrLf & _
"Contact Ron Roach or David Hall", vbCritical
SendKeys "{ESC}"
End Select
Case Is = "-BEDIT"
strUser = UCase(Environ("USERNAME"))
Select Case strUser
Case "UA02038"
Case "UA03347"
Case Else
MsgBox "B-Edit has been removed," & vbCrLf & _
"Contact Ron Roach or David Hall", vbCritical
' SendKeys "{ESC}"
ThisDrawing.SendCommand "bclose" & vbCr
End Select
Case Is = "COMMANDLINE"
Set AutoCAD = ThisDrawing.Application
End Select
End Sub
-
ahhhhh
I suck with this stuff LOL
Here is all I have so far CM
Thanks!
Mark
Private Sub ACADApp_SysVarChanged(ByVal SysvarName As String, ByVal newVal As Variant)
Select Case SysvarName
Case Is = "WSCURRENT"
Case Is = "Map Classic"
MsgBox "Do something!"
End Select
End Sub
-
what are you trying to do? I need a little more info
-
Cool! Looks good!
I bet your users love this:
MsgBox "B-Edit has been removed," & vbCrLf & _
"Contact Ron Roach or David Hall", vbCritical
-
Private Sub ACADApp_SysVarChanged(ByVal SysvarName As String, ByVal newVal As Variant)
Select Case SysvarName
Case Is = "WSCURRENT"
Dim N As String
N = GetVariable("WSCURRENT")
If N = "Map Classic" Then
MsgBox "Do something"
End If
End Select
End Sub
-
try that. Also, there is nothing special about N, I just used a single letter to capture the string
-
Well,
Right now I just want it to recognize what workspace I switched to.
It is kind of bizarre but it seems that the toolbars on the last workspace that I have active get screwy after I close ACAD.
So, I decided to try something; I made a workspace called blank.
If I first switch to blank, then close; my Map Classic workspace is fine when I re start CAD.
I have tried a number of things; I have a feeling this is another one of theses beautiful anomalies of The Cui s
So, for now, I just want it to recognize Map Classic or blank on the switch.
Pseudo:
If The system variable (wscurrent) is blank, then AutoCAD.close
Mark
-
Yes sir!
You the man!
I had a feeling I needed to use the getvariable method, just wasn't sure how to work it
Thank you sir!
Mark
-
Now if you have more than 2 workspaces, nest another SelectCase to check which 1 is loaded. For just 2, you can use the if then else and make 1 of 2 things happen
-
Well they are all loaded as they are all part of the main cui file; so I would use the case for the respective workspace that I need to work on.
Thank you sir! :)
-
Private Sub ACADApp_SysVarChanged(ByVal SysvarName As String, ByVal newVal As Variant)
Select Case SysvarName
Case Is = "WSCURRENT"
Dim N As String
N = GetVariable("WSCURRENT")
Select Case N
Case is = "Map Classic"
MsgBox "Do something #1"
Case is = "Not Map Classic"
MsgBox "Do something #2"
Case is = "3rd Choice"
MsgBox "Do something #3"
End Select
End Select
End Sub
-
Actually you are right CM
I would use the CASE statement (likely) for the different system variables and the End If conditions for the different workspaces
Mark
-
ahhhh
better yet LOL :)
Thank you!
I do try to lean towards Case statements over multiple End If statements.
The system variable change event can be pretty useful
Mark
-
FWIW, David & Mark, there is no need for the N variable......the newVal variable returned by the Event holds the value of the Sysvar of interest.
Private Sub ACADApp_SysVarChanged(ByVal SysvarName As String, ByVal newVal As Variant)
Select Case SysvarName
Case Is = "WSCURRENT"
Select Case newVal
Case is = "Map Classic"
MsgBox "Do something #1"
Case is = "Not Map Classic"
MsgBox "Do something #2"
Case is = "3rd Choice"
MsgBox "Do something #3"
End Select
End Select
End Sub
edit: changed name to value as to what is returned.
-
Yes, this works very well
Select Case SysvarName
Case Is = "WSCURRENT"
Dim WS As String
WS = GetVariable("WSCURRENT")
Select Case WS
Case Is = "Blank"
MsgBox "Do something"
End Select
End Select
WS = GetVariable ("WSCURRENT")
Then we can go on and on:
FD = GetVariable ("FILEDIA")
SDI = GetVariable ("SDI")
Excellent!
Thanks CM!
Mark
-
Oh yes!
Thanks Jeff!
This is where we began actually, I just could not get anything to happen
Actually both methods work just fine but you are right Jeff; there is no need for the get variable;
They have already accounted for that with newval
Thank you.
Mark
-
It's a bit bizarre but think of my workspace Blank as
Application.quit
Actually I will rename blank to Exit
So, now I simply doing this:
Select Case SysvarName
Case Is = "WSCURRENT"
Select Case newVal
Case Is = "Exit"
Application.Quit
Exit Sub
End Select
End Select
So, when workspace Exit is activated, exit AutoCAD
It is weird but it definitely doing what I needed.
My toolbars in Workspace Map General are now being retained.
ACAD (at least Map Enabled) does not like something about the last workspace active on exit; so I just made a dummy one I am using to exit with.
It is kind of nifty; it is like a workspace change event.
Thanks guys!
Mark