Author Topic: ACADApp_BeginQuit Event  (Read 7605 times)

0 Members and 1 Guest are viewing this topic.

Bob Wahr

  • Guest
Re: AcadDocument_BeginClose Event
« Reply #15 on: January 22, 2008, 10:44:22 AM »
You said that it did mess up your workspace when closing ACAD?
I just use vanilla acad and don't change workspaces.  Didn't really give it any thought before I did it but assumed that since my configuration was maintained that the current workspace was saved that way.  When I changed it and changed it back, everything went to default.  I just need to close the useless crap like dashboard, and redock what I need.

ML

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #16 on: January 22, 2008, 11:05:14 AM »

Yeah, I see
It really is not that big of a deal to fix my toolbars after start up; it just became a pain in the *
So, I decided to write something to address it.
Not to mention that I can draw from this code (as we all do) for future things as well.

Apparently, the workspace definition is written to the registry but not retained.
I'm not sure (at least) in my case, why it affects only the last current workspace and only in the one profile but apparently that was the problem and this seemed to have fixed it.

It is bizarre that we have to do these things to fix ACADs inefficiencies but there are quite a few bugs still lingering in the cui files. I was fine with .mns and .mnc files; they couldn't leave good enough alone? :) Although, workspaces are a great and very useful feature.

Bob:
While I have you here, can you please help me with one other thing?

If the drawing name is drawing#.dwg, on close, I want to initiate a save as if I choose yes to save via the message box.

I have this:
Code: [Select]
If ThisDrawing.Name = "Drawing" & "I need help here" & ".dwg" Then

I'm not sure how to capture the numeric value after Drawing.

My guess is it would be something like
Code: [Select]
For i = 0 to "Not sure"
 If ThisDrawing.Name = "Drawing" & (i) & ".dwg" Then
  I have the rest of the code
 End if
Next i

I'd appreciate it!

Mark











Bob Wahr

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #17 on: January 22, 2008, 12:45:37 PM »
If Left(thisdrawing.name,7) = "Drawing" Then

?

ML

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #18 on: January 22, 2008, 01:30:52 PM »

Yes! Of course
Duh! Why do I over think things so much

You are basically just filtering for the word "drawing".
Excellent!

Thanks Bob!

Bob Wahr

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #19 on: January 22, 2008, 01:35:08 PM »
Actually, for the word "Drawing"  almost through a UCASE in there, but in this instance, a new drawing should always be named "Drawing"#.dwg.

No problem.

ML

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #20 on: January 22, 2008, 01:40:35 PM »

Yes, that is true
You could use Proper in that case
Proper (Thisdrawing.name)
As you said, ACAD by deafult uses proper case Drawing.

That is cool
I always used Left(Thisdrawing.name Len(Thisdrawing.name)-4 which would achieve the same result
I like you way you are doing it; are counting 7 characters from the left as opposed to the way I way doing it, which was to trim 4 characters (.dwg) from the right.

Mark



ML

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #21 on: January 22, 2008, 01:41:49 PM »

WOW!
Excuse my spelling in the last post LOL

Thought I did a spell check :)

Mark

ML

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #22 on: January 22, 2008, 01:55:46 PM »

Bob,

I think we want to change the 7 to an 8 so that we grab the drawing number as well or we may need an Instr function.
Am I wrong here?

Mark

Bob Wahr

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #23 on: January 22, 2008, 02:27:03 PM »
Code: [Select]
For i = 0 to "Not sure"
 If ThisDrawing.Name = "Drawing" & (i) & ".dwg" Then
  I have the rest of the code
 End if
Next i

I don't know what "I have the rest of the code" is doing so I don't know.  If you need the number I would do something like this
Major psuedo-code not even trying much warning

Code: [Select]
dim strDwgNo as String 'or int dbl whatever you need from it, I assume string for new dwg name
dim strDwgNm as String
dim intDecPlc as Integer
strdwgnm = thisdrawing.name
if left(strdwgnm, 7) = "Drawing" then
  intdecplc = len(strdwgnm)-11 ' 7 for Drawing, 4 for .dwg.  The remainder of the name should be #, ##, ###
  strdwgno = mid(strdwgname,8,2)
  '"I have the rest of the code" goes here
end if

ML

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #24 on: January 22, 2008, 02:40:43 PM »

LOL

Bob!
You're going to kick my butt!  :pissed:

I was running the code with more then one drawing open; therefore your original suggestion will work just fine :)

That is:
Code: [Select]
Left(ThisDrawing.Name, 7)

All I am doing in this section is checking for (as your code does) if Drawing is in the drawing name.
If so, prompt for a save as.

First of all, most drawings are going to be saved with a real name (not drawing#), second I can not have AutoCAD prompt me for a save as dialog box; therefore, I would need to create a variable for an inputbox and type in the filename in etc. etc.
Not worth LOL
It is overkill for what I am doing

Still, your code is definitely worth keeping, I will be able to use it again.

Thanks again!
Mark

Bob Wahr

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #25 on: January 22, 2008, 03:18:09 PM »
second I can not have AutoCAD prompt me for a save as dialog box; therefore,
que?

thisdrawing.sendcommand "saveas"

ML

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #26 on: January 22, 2008, 03:28:45 PM »

Dalp!

This is true :)

Thank you sir!

Mark

ML

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #27 on: January 24, 2008, 11:13:43 AM »

Bob,
This way all I really needed
Code: [Select]
Dwgname = ThisDrawing.Name

If Left(Dwgname, 7) = "Drawing" Then
'Rest of code
End

I do that all of the time; I think about the big picture and miss the smallest things.
I guess we all do that sometimes.

I did save all of your code for future needs to filter out drawing names.

The bizarre thing here is that now that I resolved the problem with Map Enabled; now it is the last workspace (on exit) in Land Desktop that is getting thrown out of sorts. So, I can either have an exit workspace on both profiles are just simply (better idea) switch to a workspace that I do not use much on exit.

Or better yet, manually switch the workspace before exit.
Or even better then that, just say F-it! :)
What a pain in the butt.

Thanks Bob!


ML

  • Guest
Re: ACADApp_BeginQuit Event
« Reply #28 on: January 24, 2008, 01:03:23 PM »
OK, here is what I found;
I did not need to filter for the drawing name at all.
If the drawing = drawing & # and there is nothing drawn in there; then there is nothing to save.
I know, No S**t

What I wasn't realizing before was that if you haven't named the drawing yet but have drawn something, then you will automatically be prompted for a save as, so that code was not necessary to begin with; or that problem may have been a result of The BeginClose Event.Also I still had The Application.quit code in there which was forcing ACAD to close (possibly) prior to asking me if I want to save.

Also after reading over the help screen,
Quote
You should use the BeginDocClose event rather than the BeginClose event because the BeginDocClose event enables you to keep a drawing from being closed.

No events occur while a modal dialog is displayed.

So after realizing that I am now using a BeginDocClose event; I will inherently be closing ACAD (duh) so that will force the save-saveas dialog boxes to appear as normal.

I think the drawing may have been closing prior to some events firing; so it looks like BeginDocClose is the winner here.

Lastly, I am able to check for Documents.Count >= 1 and ACAD will prompt for each drawing (save-saves) in MDI Mode prior to closing out of the app.

So, the end result was that (for now) I simply created a workspace called Exit in both Land Desktop and Map Enabled so that I don't have to check for Profile, Menufile etc. etc.; this is just much easier (less code) and very easy to create. Plus, all of your (in use) workspace's toolbars should all remain just how they were left off when closing, as acad will only mess with the Exit (BS) workspaces.

The only code I needed in the end was:
Code: [Select]
Private Sub AcadDocument_BeginDocClose(Cancel As Boolean)
Dim Dwgname As String
Dim CurrSysVarData As Variant
Dim SysVarName As String
Dim NewSysVarData As String
 
Dwgname = ThisDrawing.Name
SysVarName = "WSCURRENT"

On Error GoTo Done
 If Documents.Count >= 1 Then
 'Get Current Workspace setting
  CurrSysVarData = ThisDrawing.GetVariable(SysVarName)
 End If
 If CurrSysVarData <> "Exit" Then
  NewSysVarData = "Exit"
 'Set system variable current workspace
  ThisDrawing.SetVariable SysVarName, NewSysVarData
 End If
End Sub

However, I posted the (below) code in it's entirety (using Case Statements to check for drawing name and save method) if anyone would like to refer to it.

Thanks again for the help Bob!
Mark

Code: [Select]
Private Sub AcadDocument_BeginDocClose(Cancel As Boolean)
Dim Dwgname As String
Dim CurrSysVarData As Variant
Dim SysVarName As String
Dim NewSysVarData As String
 
Dwgname = ThisDrawing.Name
SysVarName = "WSCURRENT"

On Error GoTo Done
 If Documents.Count >= 1 Then
 'Get Current Workspace setting
  CurrSysVarData = ThisDrawing.GetVariable(SysVarName)
 End If
 If CurrSysVarData <> "Exit" Then
  NewSysVarData = "Exit"
 'Set system variable current workspace
  ThisDrawing.SetVariable SysVarName, NewSysVarData
 End If
   
 Select Case Left(Dwgname, 7)
  Case Is = "Drawing"
   If MsgBox("Would you like to save this drawing?", vbYesNo) = vbYes Then
    ThisDrawing.SendCommand "saveas" & vbCr
   End If
  Case Is > "Drawing"
   If MsgBox("Would you like to save this drawing?", vbYesNo) = vbYes Then
    ThisDrawing.Save
   End If
  End Select

Done:
End Sub