Author Topic: ACADApp_BeginQuit Event  (Read 3717 times)

0 Members and 1 Guest are viewing this topic.

ML

  • Guest
ACADApp_BeginQuit Event
« on: January 18, 2008, 01:35:06 PM »

Hi
I am trying to switch my current active workspace when I close ACAD
However, I am getting an error "Failed to get the document object"
Does anyone know a workaround?

Thanks
Mark

Code: [Select]
Private Sub ACADApp_BeginQuit(Cancel As Boolean)
 Dim CurrSysVarData As Variant
 Dim SysVarName As String
 Dim NewSysVarData As String
 
 SysVarName = "WSCURRENT"
 CurrSysVarData = ThisDrawing.GetVariable(SysVarName)
 NewSysVarData = "Exit"
 
  If CurrSysVarData <> "Exit" Then
    ThisDrawing.SetVariable SysVarName, NewSysVarData
    If MsgBox("Would you like to save this drawing?", vbYesNo) = vbYes Then
     ThisDrawing.Save
     Application.Quit
    Else
     Application.Quit
     Exit Sub
    End If
  End If
End Sub

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: ACADApp_BeginQuit Event
« Reply #1 on: January 18, 2008, 02:19:03 PM »
The problem is you can close all your drawings without closing the app, and you cant make changes w/o a document being open.  What you need to do is check to see how many documents are open and if =1 set your var then close.  If doc.count > 1, do nothing
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

ML

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #2 on: January 18, 2008, 03:07:55 PM »

Cool CM!

I would not have thought of that but it makes a whole lot of sense :)
Yes, how can it do something to a document (drawing) if there is no drawing (object) to work on

Thanks!
Mark

ML

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #3 on: January 21, 2008, 10:45:19 AM »
CM

This method:
Code: [Select]
If Documents.Count > 0 Then
  GoTo Continue
Else
  Exit Sub
End If
 
Continue:
MsgBox "Do Something"

Is working in its own subroutine but it is not working along with my ACADApp_BeginQuit code.
Any idea?

If it works alone, then in theory it should get the job done. ?

Thanks!
Mark

ML

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #4 on: January 21, 2008, 11:57:56 AM »
CM

When I put that code in the app event; it still says, can not get the document object.
I wonder if it is because I am in an object level event?

Mark

ML

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #5 on: January 21, 2008, 03:17:54 PM »
OK

I think the problem here is that on the before close event (even though it says BEFORE CLOSE) I think it is closing all drawings before running the event; therefore I am getting a failed to get document error.

This is defientely an interesting one.

May be a Do While Application.documents > 0 would work.

I don't know.

Mark

Bob Wahr

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #6 on: January 21, 2008, 04:45:51 PM »
I ran into this a long time ago and was given a workaround by Randall.  Unfortunately for now, the program he gave it to me for evolved away from using it so the code is no longer there.  I'll dig through my archive when I get a chance and see if I can find it.

Just a thought though, if you are closing the drawing without saving it, it makes no difference what space you are in, correct?  The flip side of that coin is that what you really want to do is ensure that it is in the proper space at save time.  So then, you might use the BeginSave event instead.

ML

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #7 on: January 21, 2008, 05:59:09 PM »

Hey Bob

That is a very good idea, but I can not honestly say that I will be saving the drawing every time I close.

Right now I am using the ACADApp_SysVarChanged event which works fine.
I switch workspaces and that does every thing I need from there, it is just that don't I don't often remember to do that.

So, I thought it would be nice to ACAD make the switch for me on closing.

Mark



Bob Wahr

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #8 on: January 21, 2008, 06:08:37 PM »
That is a very good idea, but I can not honestly say that I will be saving the drawing every time I close.
That was exactly my point.  If you don't save the drawing, it doesn't matter what space it is in when the drawing closes because, well, you didn't save.

ML

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #9 on: January 21, 2008, 06:22:24 PM »

Oh yes, sorry I missed that.
I'm not sure (at this point) what space has to do with it, but the answer is, no it does not matter.

Mark

Bob Wahr

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #10 on: January 21, 2008, 07:09:16 PM »
Sorry, just scanned and misread the active workspace in the OP.  Give this a shot.

Code: [Select]
Private Sub AcadDocument_BeginClose()
If Documents.Count = 1 Then
 SysVarName = "WSCURRENT"
 CurrSysVarData = ThisDrawing.GetVariable(SysVarName)
 NewSysVarData = "Exit"
 
  If CurrSysVarData <> "Exit" Then
    ThisDrawing.SetVariable SysVarName, NewSysVarData
    If MsgBox("Would you like to save this drawing?", vbYesNo) = vbYes Then
     ThisDrawing.Save
     Application.Quit
    Else
     Application.Quit
     Exit Sub
    End If
  End If
End If
End Sub

And yes, I did screw up my workspace testing it.  Doh!

Bryco

  • Water Moccasin
  • Posts: 1849
Re: ACADApp_BeginQuit Event
« Reply #11 on: January 21, 2008, 08:33:59 PM »
Bob I heard you swearing from La.

Bob Wahr

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #12 on: January 21, 2008, 09:06:49 PM »
I don't doubt it for a second.

ML

  • Guest
Re: AcadDocument_BeginClose Event
« Reply #13 on: January 22, 2008, 10:17:54 AM »
Yes sir!

On that event (AcadDocument_BeginClose) it did work
Thanks Bob!

You said that it did mess up your workspace when closing ACAD?
It is a known issue but AutoDesk; if 2 menus (cui files) are sharing the same toolbars, the vertical alignment of two adjacent toolbars will get thrown off on one of the cui files (workspaces)
In my case, The toolbars in my Land.cui file (in Land Desktop are fine), it was in Map Enabled (acmap.cui) that the toolbar alignment was getting screwed up.

AutoDesk said to create a start up routine that will set your wscurrent, so I did that but quickly realized that this was not the solution. Apparently it is the current workspace upon exiting acad that gets whacked out.

Hence this work around. Let the exit workspace get screwed up, it is a dummy workspace with nothing (the minimal requirements) in it.

On the flip side, I do have a set workspace current module that gets ran on start up.
I can post that after this post, if you are interested.
It does looks like this did the job though

Thanks again
Mark

 

ML

  • Guest
Workspace current on startup
« Reply #14 on: January 22, 2008, 10:23:24 AM »
Bob
If you or anyone is interested, here is my start up code for wscurrent
It checks for the active profile, menufile (main cui) and lastly it will sets your wscurrent
Mark

Code: [Select]
Sub Acadstartup()

Dim Username As Variant
Dim WshNetwork 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"
Else
 If ActProfile = "MapLandDevelopmentDesktop" Then
 CurrMenuFile = CurrMenuPath & "acmap"
 ThisDrawing.SetVariable "wscurrent", "Map Classic"
End If
End If
 
End Sub