Author Topic: On App Activate Event  (Read 6528 times)

0 Members and 1 Guest are viewing this topic.

ML

  • Guest
On App Activate Event
« on: October 16, 2007, 12:39:42 PM »

Hi

On the App Activate Event Procedure, I am trying to run the below code however, the code is not working on App Activate; instead it is working when I minimize and amximize the App Window.
Am I using the wrong Event oe Method here?

May be I should be using the macro
Code: [Select]
Sub acadstartup()
 'code here
End Sub
Instead????

Thanks Mark

Code: [Select]
Private Sub AutoCAD_AppActivate()

Dim Preferences As AcadPreferences
Dim CurrMenuFile As String

Set Preferences = ThisDrawing.Application.Preferences
CurrMenuFile = Preferences.Files.MenuFile

Select Case CurrMenuFile
 Case Is = "Land"
  ThisDrawing.SendCommand "wscurrent" & vbCr & "Land Destop Complete" & vbCr
 Case Else
  ThisDrawing.SendCommand "wscurrent" & vbCr & "Map Classic" & vbCr
End Select

End Sub

quamper

  • Guest
Re: On App Activate Event
« Reply #1 on: October 16, 2007, 02:02:25 PM »
Are you trying to do something on activation or something else like on loading? Activation is what you are talking about.. if the program is in the background and then you select it, or unminimizing you've just "activated" the application.

See this msdn article http://msdn2.microsoft.com/en-us/library/dyz95fhy(VS.80).aspx

ML

  • Guest
Re: On App Activate Event
« Reply #2 on: October 16, 2007, 02:03:53 PM »

Yes

I was referring to on startup

Mark

ML

  • Guest
Re: On App Activate Event
« Reply #3 on: October 16, 2007, 02:17:36 PM »

OK

I have an acadstartup macro in my acad.dvb file
with the above (first post) code in it.

I am initializing VBA by having acvba.arx inside my acad.rx file.
I also have my acad.dvb file in Startup Suite.

Also, here is proof that VBA is initializing and running my startup macro:
After I start ACAD, I hit F2 and get this:
However, my workspace is not physically switching to Map Classic
Any ideas?????

Initializing VBA System...
Loading VBA startup file...wscurrent
Map Classic

Guest

  • Guest
Re: On App Activate Event
« Reply #4 on: October 16, 2007, 02:40:56 PM »
Instead of SendCommand, try this...

ThisDrawing.SetVariable("wscurrent", "Map Classic")

...since the Work Space is a system variable.


I've never really had much luck with SendCommand.   :-(

ML

  • Guest
Re: On App Activate Event
« Reply #5 on: October 16, 2007, 02:44:39 PM »

Matt
That is a great idea!

You are right, it is a system variable DUH :)
That would be much better then the send command.

The send command certainly does have some use but I try to avoid it when possible.

The interesting thing is that the macro works fine if I run it from within ACAD but not on startup

I think you just touched on something; I don't think VBA likes the idea of sending commands to the command line on startup

Let's see

Thanks

Mark

Guest

  • Guest
Re: On App Activate Event
« Reply #6 on: October 16, 2007, 02:46:49 PM »
Good luck!

ML

  • Guest
Re: On App Activate Event
« Reply #7 on: October 16, 2007, 02:55:40 PM »

THanks Matt!

The only problem is that this syntax
Code: [Select]
ThisDrawing.SetVariable("wscurrent", "Map Classic")
is incorrect

So, first I am trying to work that out

Mark

Guest

  • Guest
Re: On App Activate Event
« Reply #8 on: October 16, 2007, 02:57:52 PM »

THanks Matt!

The only problem is that this syntax
Code: [Select]
ThisDrawing.SetVariable("wscurrent", "Map Classic")
is incorrect

So, first I am trying to work that out

Mark

Yeah, you're right.  I was messing around with it and had MsgBox in front of it.  Just remove the parentheseseseses and you should be all set.

ML

  • Guest
Re: On App Activate Event
« Reply #9 on: October 16, 2007, 02:59:39 PM »

Nope, that doesn't work either LOL

Don't you love it, it is always the small things :)

It probably has to be setvariable wscurrent = etc etc

ML

  • Guest
Re: On App Activate Event
« Reply #10 on: October 16, 2007, 03:14:36 PM »

Matt

The help screen says

Code: [Select]
Dim strData As String
 sysVarName = "DCTCUST"
 strData = "My Custom Dictionary"
 sysVarData = strData        ' String data
 ThisDrawing.SetVariable sysVarName, sysVarData

This tells me

I need

Code: [Select]
ThisDrawing.SetVariable("wscurrent", Map Classic)

but this method is not working????????

I never have a problem when I use getvariable

Mark


ML

  • Guest
Re: On App Activate Event
« Reply #11 on: October 16, 2007, 03:17:36 PM »

Actually
I take that back; according to the help, it should be
Code: [Select]
ThisDrawing.SetVariable ("wscurrent", "Map Classic")

But I got it

It is this:
Code: [Select]
ThisDrawing.SetVariable "wscurrent", "Map Classic"

Now, I can get back to the original problem :)






ML

  • Guest
Re: On App Activate Event
« Reply #12 on: October 16, 2007, 03:23:04 PM »

I am having a post with myself here :lol:

The help screen was correct the whole time; it is my brain that is not right  :lol: :)

Ok, well that did it!

No sendcommand  in The acadstartup

So, in my Acadstartup macro
I have:

Code: [Select]
Sub Acadstartup()
Set AutoCAD = ThisDrawing.Application

Dim Preferences As AcadPreferences
Dim CurrMenuFile As String

Set Preferences = ThisDrawing.Application.Preferences
CurrMenuFile = Preferences.Files.MenuFile

Select Case CurrMenuFile
 Case Is = "Land"
   ThisDrawing.SetVariable "wscurrent", "Land Destop Complete"
 Case Else
   ThisDrawing.SetVariable "wscurrent", "Map Classic"
End Select

End Sub

All seems to be working well

Thanks for the clue Matt!

Mark

Guest

  • Guest
Re: On App Activate Event
« Reply #13 on: October 16, 2007, 03:30:14 PM »
Is this a typo??

Quote
ThisDrawing.SetVariable "wscurrent", "Land Destop Complete"

Should there be a K in there??!?

ML

  • Guest
Re: On App Activate Event
« Reply #14 on: October 16, 2007, 03:33:39 PM »

Yes, it is thank you :)
That's all I need is to spend another 30 minutes figuring that one out LOL

Mark

Guest

  • Guest
Re: On App Activate Event
« Reply #15 on: October 16, 2007, 03:34:48 PM »
Glad you got it working!


Now get back to work!!

ML

  • Guest
Re: On App Activate Event
« Reply #16 on: October 16, 2007, 03:36:26 PM »

Yeah, yeah!

I see you are using Land Desktop and Civil 3D   :-)


Guest

  • Guest
Re: On App Activate Event
« Reply #17 on: October 16, 2007, 04:12:25 PM »
...and MEP (God help me) and Architecture.

Well, not really using them any more.  I "support" them.  I've graduated from CADD Monkey to CADD Manager/3D Modeler-Man.



I'm also pretty good with Notepad!   :wink:

ML

  • Guest
Re: On App Activate Event
« Reply #18 on: October 16, 2007, 05:54:23 PM »

Yep

I hear you; I do support, development and help develop CAD Standards.
I have certainly done my share of CAD

I must admit, I sometimes miss some of The Design work I have done in the past but I'm not sure I want to be a manager.

Land Desktop and Civil Design in general is new to me
While I help The CAD/It Manager develop routines and standards, I still have a lot to learn about Land Desktop and Civil Design.

Hopefully I can get in on occasion and do some design work as well.

Mark





ML

  • Guest
Re: On App Activate Event
« Reply #19 on: October 17, 2007, 10:43:02 AM »

Matt
I just thought I would share this with you:

My WsCurrent Module gets fired up on startup, so when I fired up Land Desktop this morning,
I was gettign an error, System Variable can not be set.
It was overlooking The Main (Menufile) cui Land and going to Workspace Map Classic which obviosuly does not exist in the land cui file.

After playing around a bit, I realized that the code was looking for the whole path to the main cui file Land.
That sort of suprises me as we have a path to the main cui and I would think that would have been picked up.
Anyhow, after putting in the path, it did resolve it.

The code is below:

Mark


Code: [Select]
Sub WsCurrent()

Dim Username As Variant
Dim Preferences As AcadPreferences
Dim CurrMenuPath As String
Dim CurrMenuFile As String

Set WshNetwork = CreateObject("WScript.Network")
Set Preferences = ThisDrawing.Application.Preferences

Username = WshNetwork.Username
CurrMenuPath = "C:\Documents and Settings\" & Username & "\Application Data\Autodesk\Autodesk Land Desktop 2006\R16.2\enu\Support\"
CurrMenuFile = Preferences.Files.MenuFile

Select Case CurrMenuFile
 Case Is = CurrMenuPath & "land"
  ThisDrawing.SetVariable "wscurrent", "Land Destop Complete"
 Case Else
  ThisDrawing.SetVariable "wscurrent", "Map Classic"
End Select


End Sub

Guest

  • Guest
Re: On App Activate Event
« Reply #20 on: October 17, 2007, 10:46:43 AM »
Cool!

ML

  • Guest
Re: On App Activate Event
« Reply #21 on: October 17, 2007, 11:02:10 AM »

Yes sir!

Now, the explanation as to why I got into this whole thing LOL
Yes, it is easy enough to manually set what workspace you want current, however I noticed that when I switched workspaces, with some of them that I set up, the toolbars would be all wacked out and not like I had set them.

So, after reading about it; the article said that when you setup the toolbars in your workspace, those changes get written to the registry however, once ACAD is closed, the changes are not saved in the registry.

I can not explain why I did not have that problem in Land Desktop but I did with Map General.
So, the article suggested using a startup routine to set current in CAD what workspace you want current on startup and your workspace changes will be retained.

It doesn't necessarily make sense but I am not surprised as these cui files have many flaws.

So, now I will set up my Map Classic Workspace precise how I want it and see if the changes do get maintained.

Mark


ML

  • Guest
Re: On App Activate Event
« Reply #22 on: October 17, 2007, 11:12:53 AM »

Well, htat did not fix the problem; I guess I will need to read more on workspaces when I have time.

Still the code can be useful for other purposes I'm sure :)

Mark

ML

  • Guest
Re: On App Activate Event
« Reply #23 on: October 17, 2007, 03:04:53 PM »

Man oh Man

It gets even deeper now.
I didn't think about the profiles.

For example, if Land Desktop is already open, then the starup routine in The Acad.dvb file is saying, OK
Land is the (menufile) main cui.

Now, if I open Map Enabled, the macro (from the same acad.dvb file) is started again and I believe it is seeing Land as the main cui from Land Desktop and telling me that the system variable can not be set.

On top of that, if royally F'd up my MapGeneral profile,  :pissed:
So, luckily I had that backed up and restored it.

So, this is interesteing, I have 2 Versions of ACAD sharing the same acad.dvb file.
So, what I think I will need to do is first,
Check for profile:

If profile = LandDesktop then
 The rest of my code
Else
 The rest of my code
End if

Mark

Guest

  • Guest
Re: On App Activate Event
« Reply #24 on: October 17, 2007, 03:10:45 PM »
 :lmao:

Better you than me!  (are you sure manually setting the workspace isn't a better option at this point?)

ML

  • Guest
Re: On App Activate Event
« Reply #25 on: October 17, 2007, 03:15:25 PM »

LOL

Actually, if it doesn't fix the toolbar-workspace problem which it doen't seem to be doing, then yes, I will scrap it.
However, adding the profile part is easy.

If I find the post about workspaces and toolbars not being retained, I will post it.

The good thing is that people are starting LandDesktop with The LandDEsktop profile and MapGeneral with The MapGeneral Profile as they are switches /profile in the startup icon. So, that is pretty fixed.

It still never hurts to have the code written, I am sure I can utilize it later in some other project.

Mark

ML

  • Guest
Re: On App Activate Event
« Reply #26 on: October 18, 2007, 10:46:57 AM »

Matt

Here is that article
Now you will better understand why I am writing this code (time permitting)
However, the article is usuing a LISP startup and I am using THe ACAD acadstartup method.
Still, it doesn't seem to be fixing the problem; then again the problem may be because I am using The Same acad.dvb file for both versions of CAD. Not sure

Mark


http://usa.autodesk.com/adsk/servlet/ps/item?siteID=123112&id=7313141&linkID=9240617

ML

  • Guest
Re: On App Activate Event
« Reply #27 on: October 18, 2007, 10:48:19 AM »

And yes, I should be using spell check :)

BTW: If you were once a CAD Monkey; does that now make you a zoo keeper :)

Mark

Guest

  • Guest
Re: On App Activate Event
« Reply #28 on: October 18, 2007, 10:51:37 AM »

And yes, I should be using spell check :)

BTW: If you were once a CAD Monkey; does that now make you a zoo keeper :)

Mark

Some days it feels more like a babysitter.  :wink:

ML

  • Guest
Re: On App Activate Event
« Reply #29 on: October 18, 2007, 10:54:55 AM »

In this case; better you then me LOL
I think I'd rather be stuck on code :)

However, I can say been there, F-that! LOL

ML

  • Guest
Re: On App Activate Event
« Reply #30 on: October 18, 2007, 11:26:29 AM »

OK, well, here is my last attempt
The code works well but it still did not resolve the problem
DAM cui files!  :pissed:

The below code will check for your Active Profile,
Your current menu (main cui) file
Then set the workspace you want to be current.

Thanks again Matt!

Mark

Code: [Select]
Sub WsCurrent()

Dim Username As Variant
Dim Preferences As AcadPreferences
Dim ActProfile As String
Dim CurrMenuPath As String
Dim CurrMenuFile As String


Set WshNetwork = CreateObject("WScript.Network")
Set Preferences = ThisDrawing.Application.Preferences

Username = WshNetwork.Username
ActProfile = Preferences.Profiles.ActiveProfile
CurrMenuPath = "C:\Documents and Settings\" & Username & "\Application Data\Autodesk\Autodesk Land Desktop 2006\R16.2\enu\Support\"
CurrMenuFile = Preferences.Files.MenuFile


If ActProfile = "Land Desktop" Then
  Select Case CurrMenuFile
   Case Is = CurrMenuPath & "land"
   ThisDrawing.SetVariable "wscurrent", "Land Destop Complete"
  End Select
End If
If ActProfile = "MapGeneral" Then
  Select Case CurrMenuFile
   Case Is = CurrMenuPath & "acmap"
   ThisDrawing.SetVariable "wscurrent", "Map Classic"
  End Select
End If

End Sub

Guest

  • Guest
Re: On App Activate Event
« Reply #31 on: October 19, 2007, 05:54:04 PM »
It's NOT gonna work because you STILL haven't spelled it correctly!!!

Quote
ThisDrawing.SetVariable "wscurrent", "Land Destop Complete"


 :wink: :-)

ML

  • Guest
Re: On App Activate Event
« Reply #32 on: October 19, 2007, 05:55:15 PM »

LOL

Good catch! :)

Mark

ML

  • Guest
Re: On App Activate Event
« Reply #33 on: October 19, 2007, 05:55:33 PM »

Have a great weekend man!

ML

  • Guest
Re: On App Activate Event
« Reply #34 on: October 31, 2007, 10:49:29 AM »

OK, I definetely got it now and it is doing exactly what the article said
On startup, set the workspace that you want current to be current.

This fixed my toolbar location problem; they are now being retained on each start of ACAD.
I think my earlier approach to the coding was the reason it was not working.

If anyone is interested; here is my approach and code:
Again, for me, it is working just fine.

Mark

On Startup, in The acad.dvb file
Code: [Select]
Sub Acadstartup()
Set AutoCAD = ThisDrawing.Application

RunMacro ("WsCurrent")  '<----- This is calling my WsCurrent Module

End Sub

WsCurrent Module:

Code: [Select]
Sub WsCurrent()

Dim Username As Variant
Dim Preferences As AcadPreferences
Dim ActProfile As String
Dim CurrMenuPath As String
Dim CurrMenuFile As String

Set WshNetwork = CreateObject("WScript.Network")
Set Preferences = ThisDrawing.Application.Preferences

Username = WshNetwork.Username
ActProfile = Preferences.Profiles.ActiveProfile
CurrMenuPath = "C:\Documents and Settings\" & Username & "\Application Data\Autodesk\Autodesk Land Desktop 2006\R16.2\enu\Support\"
CurrMenuFile = Preferences.Files.MenuFile


If ActProfile = "Land Desktop" Then
 CurrMenuFile = CurrMenuPath & "land"
 ThisDrawing.SetVariable "wscurrent", "Land Destop Complete"
End If
If ActProfile = "MapGeneral" Then
 CurrMenuFile = CurrMenuPath & "acmap"
 ThisDrawing.SetVariable "wscurrent", "Map Classic"
End If

End Sub