TheSwamp

Code Red => VB(A) => Topic started by: ML on January 11, 2008, 12:36:03 PM

Title: SysVarChanged Event?
Post 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

Code: [Select]
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
Title: Re: SysVarChanged Event?
Post by: Jeff_M on January 11, 2008, 01:40:53 PM
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)
Code: [Select]
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
Title: Re: SysVarChanged Event?
Post by: ML on January 11, 2008, 02:01:14 PM

Hey Jeff

That is not doing it either. hummmmm

Any other ideas?

THanks!

Mark
Title: Re: SysVarChanged Event?
Post by: Jeff_M on January 11, 2008, 02:19:42 PM
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:
Title: Re: SysVarChanged Event?
Post by: ML on January 11, 2008, 02:29:48 PM
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

Title: Re: SysVarChanged Event?
Post by: ML on January 11, 2008, 03:25:52 PM

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

Code: [Select]
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
Title: Re: SysVarChanged Event?
Post by: David Hall on January 11, 2008, 04:17:49 PM
I actually use that to prevent my users from using BEdit
Title: Re: SysVarChanged Event?
Post by: ML on January 11, 2008, 04:56:10 PM

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
Title: Re: SysVarChanged Event?
Post by: ML on January 11, 2008, 04:58:17 PM

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
Title: Re: SysVarChanged Event?
Post by: David Hall on January 11, 2008, 04:59:16 PM
Post what you have so far
Title: Re: SysVarChanged Event?
Post by: David Hall on January 11, 2008, 05:00:44 PM
Code: [Select]
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
Title: Re: SysVarChanged Event?
Post by: ML on January 11, 2008, 05:03:17 PM

ahhhhh

I suck with this stuff LOL
Here is all I have so far CM

Thanks!
Mark

Code: [Select]
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
Title: Re: SysVarChanged Event?
Post by: David Hall on January 11, 2008, 05:05:37 PM
what are you trying to do?  I need a little more info
Title: Re: SysVarChanged Event?
Post by: ML on January 11, 2008, 05:05:42 PM

Cool! Looks good!

I bet your users love this:

Code: [Select]
MsgBox "B-Edit has been removed," & vbCrLf & _
                         "Contact Ron Roach or David Hall", vbCritical

Title: Re: SysVarChanged Event?
Post by: David Hall on January 11, 2008, 05:10:08 PM
Code: [Select]
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
Title: Re: SysVarChanged Event?
Post by: David Hall on January 11, 2008, 05:10:48 PM
try that.  Also, there is nothing special about N, I just used a single letter to capture the string
Title: Re: SysVarChanged Event?
Post by: ML on January 11, 2008, 05:12:06 PM
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
Title: Re: SysVarChanged Event?
Post by: ML on January 11, 2008, 05:14:30 PM

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
Title: Re: SysVarChanged Event?
Post by: David Hall on January 11, 2008, 05:18:40 PM
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
Title: Re: SysVarChanged Event?
Post by: ML on January 11, 2008, 05:20:03 PM

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! :)

Title: Re: SysVarChanged Event?
Post by: David Hall on January 11, 2008, 05:25:08 PM
Code: [Select]
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
Title: Re: SysVarChanged Event?
Post by: ML on January 11, 2008, 05:25:35 PM
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
Title: Re: SysVarChanged Event?
Post by: ML on January 11, 2008, 05:27:39 PM

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
Title: Re: SysVarChanged Event?
Post by: Jeff_M on January 11, 2008, 05:33:03 PM
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.
Code: [Select]
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.
Title: Re: SysVarChanged Event?
Post by: ML on January 11, 2008, 05:35:19 PM

Yes, this works very well

Code: [Select]
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
Title: Re: SysVarChanged Event?
Post by: ML on January 11, 2008, 05:38:25 PM

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
Title: Re: SysVarChanged Event?
Post by: ML on January 11, 2008, 05:57:36 PM

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:

Code: [Select]
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