TheSwamp
Code Red => VB(A) => Topic started by: ML 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
Sub acadstartup()
'code here
End Sub
Instead????
Thanks Mark
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
-
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
-
Yes
I was referring to on startup
Mark
-
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
-
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. :-(
-
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
-
Good luck!
-
THanks Matt!
The only problem is that this syntax
ThisDrawing.SetVariable("wscurrent", "Map Classic")
is incorrect
So, first I am trying to work that out
Mark
-
THanks Matt!
The only problem is that this syntax
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.
-
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
-
Matt
The help screen says
Dim strData As String
sysVarName = "DCTCUST"
strData = "My Custom Dictionary"
sysVarData = strData ' String data
ThisDrawing.SetVariable sysVarName, sysVarData
This tells me
I need
ThisDrawing.SetVariable("wscurrent", Map Classic)
but this method is not working????????
I never have a problem when I use getvariable
Mark
-
Actually
I take that back; according to the help, it should be
ThisDrawing.SetVariable ("wscurrent", "Map Classic")
But I got it
It is this:
ThisDrawing.SetVariable "wscurrent", "Map Classic"
Now, I can get back to the original problem :)
-
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:
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
-
Is this a typo??
ThisDrawing.SetVariable "wscurrent", "Land Destop Complete"
Should there be a K in there??!?
-
Yes, it is thank you :)
That's all I need is to spend another 30 minutes figuring that one out LOL
Mark
-
Glad you got it working!
Now get back to work!!
-
Yeah, yeah!
I see you are using Land Desktop and Civil 3D :-)
-
...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:
-
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
-
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
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
-
Cool!
-
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
-
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
-
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
-
:lmao:
Better you than me! (are you sure manually setting the workspace isn't a better option at this point?)
-
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
-
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
(http://usa.autodesk.com/adsk/servlet/ps/item?siteID=123112&id=7313141&linkID=9240617)
-
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
-
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:
-
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
-
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
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
-
It's NOT gonna work because you STILL haven't spelled it correctly!!!
ThisDrawing.SetVariable "wscurrent", "Land Destop Complete"
:wink: :-)
-
LOL
Good catch! :)
Mark
-
Have a great weekend man!
-
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
Sub Acadstartup()
Set AutoCAD = ThisDrawing.Application
RunMacro ("WsCurrent") '<----- This is calling my WsCurrent Module
End Sub
WsCurrent Module:
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