.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Endsave is triggered for AutoSave as well

7 REPLIES 7
Reply
Message 1 of 8
danvang
923 Views, 7 Replies

Endsave is triggered for AutoSave as well

I want to run a custom command after a save (QSAVE or SAVEAS) occurs. The following code works but it also gets run when an Autosave occurs as well. Does anyone know of a way to ignore the Autosave and have it only run when QSAVE or SAVEAS is run. Any help would be greatly appreciated. Thanks!

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Imports Autodesk.AutoCAD.ApplicationServices

<Assembly: ExtensionApplication(GetType(Autodesk.AutoCAD.ACADAutoSaveDWF.AutoSave))>

Namespace Autodesk.AutoCAD.ACADAutoSaveDWF
    Public Class AutoSave
        Implements IExtensionApplication

        Public WithEvents ThisDrawing As AcadDocument = Application.DocumentManager.MdiActiveDocument.AcadDocument
        Public WithEvents docs As DocumentCollection = Application.DocumentManager

        Private Sub docs_DocumentActivated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs) Handles docs.DocumentActivated
            ThisDrawing = e.Document.AcadDocument
        End Sub

        Private Sub AcadDocument_QSave() Handles ThisDrawing.EndSave
            ThisDrawing.Utility.Prompt("Save has occurred")
        End Sub

        Public Sub Initialize() Implements IExtensionApplication.Initialize

        End Sub

        Public Sub Terminate() Implements IExtensionApplication.Terminate

        End Sub
    End Class
End Namespace

** If my reply resolves this issue, please choose "Accept as Solution" **
Dan Vang
7 REPLIES 7
Message 2 of 8
caddzone
in reply to: danvang

You can't tell AutoCAD to not fire the event for AutoSaves, so the

only option is to look at the extension of the file being saved to, and

if it is "sv$" then do nothing.

 

Also, if you are making changes to the drawing in the event,

then it may be appropriate to not ignore AuotSaves, because

that creates a backup of the DWG file in case something goes

wrong, and in that case, if the autosaved file is restored, then

whatever you are doing in the event will be missing from the

file.



AcadXTabs for AutoCAD
Supporting AutoCAD 2000-2011


Message 3 of 8
danvang
in reply to: caddzone

Thanks. I'll have to try looking for the sv$ or try something else. Maybe like undefining the QSAVE or the SAVEAS commands and redefined to a custom save. No sure what's the best way yet.

 

BTW, the goals is to generate a dwf upon save. So I don't want it to run when the autosave occurs otherwise a dwf is always being created every 10 or 15 mins. That's unnecessary steps that ACAD has to do.

 

Thanks!

** If my reply resolves this issue, please choose "Accept as Solution" **
Dan Vang
Message 4 of 8
danvang
in reply to: danvang

I got my answer....... I think. Well it works. Instead of watching the EndSave. I am watching for EndCommand. Then filtering it out for only QSAVE and SAVEAS. Now how do I filter it out if they click Close and choose Yes to save the drawing? hummmmm.

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~`

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Imports Autodesk.AutoCAD.ApplicationServices

<Assembly: ExtensionApplication(GetType(Autodesk.AutoCAD.ACAD AutoSaveDWF.AutoSave))>

Namespace Autodesk.AutoCAD.ACADAutoSaveDWF
    Public Class AutoSave
        Implements IExtensionApplication

        Public WithEvents ThisDrawing As AcadDocument = Application.DocumentManager.MdiActiveDocument.AcadDocument
        Public WithEvents docs As DocumentCollection = Application.DocumentManager

        Private Sub docs_DocumentActivated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs) Handles docs.DocumentActivated
            ThisDrawing = e.Document.AcadDocument
        End Sub

        Private Sub AcadDocument_QSave(ByVal CommandName as String) Handles ThisDrawing.EndCommand
            If CommandName = "QSAVE" or CommandName = "SAVEAS" then

                  ThisDrawing.Utility.Prompt("Save has occurred")

           End If
        End Sub

        Public Sub Initialize() Implements IExtensionApplication.Initialize

        End Sub

        Public Sub Terminate() Implements IExtensionApplication.Terminate

        End Sub
    End Class
End Namespace

** If my reply resolves this issue, please choose "Accept as Solution" **
Dan Vang
Message 5 of 8
caddzone
in reply to: danvang

Sorry, that's a bad idea.

 

Saves can be done without issuing either of those commands,

as is the case of CLOSE or QUIT, as well as other means.

 

It's not easy to tell how the user answers the prompt and there

is no reason to jump through that hoop because you can just

check the file extension in the EndSave event.

 

You should be able to get the filename being saved to from

either of these sysvars:

 

    SAVEFILE

    SAVEFILEPATH

 

With that you only need to check the extension to

see if its an autosave or a user-save.

 

 



AcadXTabs for AutoCAD
Supporting AutoCAD 2000-2011


Message 6 of 8
danvang
in reply to: caddzone

Thanks for the input! It is appreciated.

 

I didn't get a chance to work on this until now but here is my code. It seems to work. This just the sub

 

~~~~~~~~~~~~~~~~

Private Sub AcadDocument_QSave(ByVal FileName as String) Handles ThisDrawing.EndSave

       Dim intExtLoc As Integer = FileName.Count - 3

       Dim strExtension as String = FileName.Substring(intExtLoc,3).ToUpper

       If strExtension = "DWG" then
            ThisDrawing.Utility.Prompt("Save has occurred")

       End If
        End Sub

~~~~~~~~~~~~~~~

The only issue I am running into, which is minor I think, is when I run the code to plot the DWG to generate the dwf. At the end looks like a temporary save occurs. The saved file has a DWG extension as well but has ".0." before the extension. For example, Drawing1.0.dwg, Floorplan.0.dwg, etc. So I will have to do another check which will be simple enough. But now i am wondering how many commands will trigger a temporay save like the plot.

 

 

** If my reply resolves this issue, please choose "Accept as Solution" **
Dan Vang
Message 7 of 8
joantopo
in reply to: danvang

I create the commandEnded event within the DocumentCreated event.

 

  doc.CommandEnded += OnCommandEnded;

 

Then, function is:

 

  static void OnCommandEnded(object sender, CommandEventArgs e)
        {
            string comando = e.GlobalCommandName.ToLower();

           if (comando=="qsave" || comando=="saveas")
            {
              //call your command
            }
        }

 

Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes
Message 8 of 8
joantopo
in reply to: joantopo

Hi @caddzone

 

Mi situation is the opposite case.

 

I want to catch the "QSAVE", "SAVEAS" and AUTO_SAVE, but AUTO_SAVE is not a command. 

 

I need to catch them before saving the document, so I use the CommandWillStart event for (QSAVE, SAVEAS) commands.

 

But... how can I catch the "AUTO_SAVE" routine before saving the document?

 

I read this (waiting for any response)

http://adndevblog.typepad.com/autocad/2012/08/about-autosave-and-notificationsevents.html

 

 

Thanks.

 

Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost