<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to catch  Save/Quit Document? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8313503#M24648</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your time and expertise.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Janet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Oct 2018 16:52:34 GMT</pubDate>
    <dc:creator>JanetDavidson</dc:creator>
    <dc:date>2018-10-04T16:52:34Z</dc:date>
    <item>
      <title>How to catch  Save/Quit Document?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8312702#M24644</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;&lt;P&gt;I have a routine which listen to Save Document command and then write&amp;nbsp; some Data to Document Dictionary.&lt;/P&gt;&lt;P&gt;The problem&amp;nbsp; is when user click on top right 'X' to quit and then when Auto-CAD prompts for saving , my routine crashes.&lt;/P&gt;&lt;P&gt;What is the best approach to catch if user clicks the 'X' and if user wants to save the document before document closes&amp;nbsp; data to be written to Dictionary?&lt;/P&gt;&lt;P&gt;Thanks in Advance.&lt;/P&gt;&lt;P&gt;Janet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 12:26:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8312702#M24644</guid>
      <dc:creator>JanetDavidson</dc:creator>
      <dc:date>2018-10-04T12:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to catch  Save/Quit Document?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8312775#M24645</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should try to handle the &lt;A href="https://help.autodesk.com/view/OARX/2019/ENU/?guid=OREFNET-Autodesk_AutoCAD_ApplicationServices_Document_BeginDocumentClose" target="_blank"&gt;Document.BeginDocumentClose envent&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 12:47:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8312775#M24645</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-10-04T12:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to catch  Save/Quit Document?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8313293#M24646</link>
      <description>&lt;P&gt;Hello Gile and Thank you&amp;nbsp; for replying back to me.&lt;/P&gt;&lt;P&gt;If I use that Event&amp;nbsp;how would I know if user is pressing Yes or No when program asking " Save Change to C:\BlahBlah.dwg ?"&lt;/P&gt;&lt;P&gt;I don't want to save database if user pressing No.&lt;/P&gt;&lt;P&gt;I summarized the code below for your review.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Public Class AllCommandAndInitialize
    Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
    Public Sub Initialize() Implements IExtensionApplication.Initialize
        AddHandler Application.DocumentManager.DocumentCreated, AddressOf StartUpEvents.On_Document_Created
    End Sub
    Public Sub Terminate() Implements IExtensionApplication.Terminate
    End Sub
    Class StartUpEvents
        Shared Sub On_Document_Created(sender As Object, e As DocumentCollectionEventArgs)
            AddHandler Application.DocumentManager.CurrentDocument.BeginDocumentClose, AddressOf StartUpEvents.OnBeginDocumentClose
        End Sub
        Shared Sub OnBeginDocumentClose(sender As Object, e As DocumentBeginCloseEventArgs)
            'If user presses 'Yes' to "Save c:\blahblah.dwg"   then
            '       draw a line and save database.
            'else
            '      do nothing.
            ' end if 
        End Sub
    End Class
End Class&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 15:30:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8313293#M24646</guid>
      <dc:creator>JanetDavidson</dc:creator>
      <dc:date>2018-10-04T15:30:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to catch  Save/Quit Document?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8313443#M24647</link>
      <description>&lt;P&gt;You can handle the &lt;A href="https://help.autodesk.com/view/OARX/2019/ENU/?guid=OREFNET-Autodesk_AutoCAD_DatabaseServices_Database_BeginSave" target="_blank"&gt;Database.BeginSave&lt;/A&gt; or the &lt;A href="https://help.autodesk.com/view/OARX/2019/ENU/?guid=OREFNET-Autodesk_AutoCAD_DatabaseServices_Database_SaveComplete" target="_blank"&gt;Database.SaveComplete&lt;/A&gt; event&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;    public class Initialization : IExtensionApplication
    {
        public void Initialize()
        {
            var docMan = Application.DocumentManager;
            docMan.DocumentCreated += DocumentManager_DocumentCreated;
            foreach (Document doc in docMan)
            {
                doc.Database.SaveComplete += Database_SaveComplete;
            }
        }

        private void DocumentManager_DocumentCreated(object sender, DocumentCollectionEventArgs e)
        {
            e.Document.Database.SaveComplete += Database_SaveComplete;
        }

        private void Database_SaveComplete(object sender, DatabaseIOEventArgs e)
        {
            // do your stuff here
        }

        public void Terminate()
        { }
    }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 16:42:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8313443#M24647</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-10-04T16:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to catch  Save/Quit Document?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8313503#M24648</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your time and expertise.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Janet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 16:52:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8313503#M24648</guid>
      <dc:creator>JanetDavidson</dc:creator>
      <dc:date>2018-10-04T16:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to catch  Save/Quit Document?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8316357#M24649</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&lt;/P&gt;&lt;P&gt;I apologize for hijacking, but this is 'very' close in topic to a thread I was going to make.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So lets say a user is Closing/Saving a DWG,&amp;nbsp; we can catch that with the event handlers.&amp;nbsp; But utilizing those event handlers, is there anyway to stop the DWG from closing if we wanted to within that Event Handler?&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 18:56:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8316357#M24649</guid>
      <dc:creator>mhillis</dc:creator>
      <dc:date>2018-10-05T18:56:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to catch  Save/Quit Document?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8316404#M24650</link>
      <description>&lt;P&gt;As explained in &lt;A href="https://help.autodesk.com/view/OARX/2019/ENU/?guid=OREFNET-Autodesk_AutoCAD_ApplicationServices_Document_BeginDocumentClose" target="_blank"&gt;the docs&lt;/A&gt;, if you handle Document.DocumentBeginClose event, you "can call &lt;SPAN class="Element146"&gt;DocumentBeginCloseEventArgs.Veto()&lt;/SPAN&gt; during this notification to stop AutoCAD from shutting down the document."&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 19:20:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8316404#M24650</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-10-05T19:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to catch  Save/Quit Document?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8316460#M24651</link>
      <description>&lt;P&gt;Thanks for the quick reply!&amp;nbsp; I should have specified this further in my initial post, but I do want to be able to veto the close after the save has been performed.&amp;nbsp; I'll need to look&amp;nbsp; into it and mess around with it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 19:56:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8316460#M24651</guid>
      <dc:creator>mhillis</dc:creator>
      <dc:date>2018-10-05T19:56:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to catch  Save/Quit Document?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8321235#M24652</link>
      <description>&lt;P&gt;Hello Gile&lt;/P&gt;&lt;P&gt;I am not sure why this don't work. I followed what you suggested.&lt;/P&gt;&lt;P&gt;still I don't see what I expect to see. I click on 'X' and when get prompt to save, I say save. after opening the DWG file I don't see the line in there. Would you mind please.&lt;/P&gt;&lt;PRE&gt;Public Class AllCommandAndInitialize
        Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
    Public Sub Initialize() Implements IExtensionApplication.Initialize
        AddHandler Application.DocumentManager.DocumentCreated, AddressOf StartUpEvents.On_Document_Created
    End Sub
    Public Sub Terminate() Implements IExtensionApplication.Terminate
    End Sub
    Class StartUpEvents
            Shared Sub On_Document_Created(sender As Object, e As DocumentCollectionEventArgs)
            AddHandler Application.DocumentManager.CurrentDocument.BeginDocumentClose, AddressOf StartUpEvents.OnBeginDocumentClose
        End Sub

        Shared Sub OnBeginDocumentClose(sender As Object, e As DocumentBeginCloseEventArgs)
                AddHandler Application.DocumentManager.MdiActiveDocument.Database.SaveComplete, AddressOf OnSaveComplete
            End Sub

            Private Shared Sub OnSaveComplete(sender As Object, e As DatabaseIOEventArgs)
                Dim Mydwg As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
                Dim MyDb As Database = Mydwg.Database

                Using MyDb
                    Using tr As Transaction = MyDb.TransactionManager.StartTransaction
                        Try
                            Dim mybtr As BlockTableRecord = CType(tr.GetObject(MyDb.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
                            Dim myline As Line = New Line(New Point3d(0, 0, 0), New Point3d(10000, 10000, 0))

                            mybtr.AppendEntity(myline)
                            tr.AddNewlyCreatedDBObject(myline, True)
                            tr.Commit()
                            Autodesk.AutoCAD.ApplicationServices.DocumentExtension.CloseAndSave(Mydwg, Mydwg.Name)
                        Catch ex As Autodesk.AutoCAD.Runtime.Exception
                            MsgBox(ex.StackTrace)
                        End Try
                    End Using
                End Using
            End Sub
        End Class
    End Class&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Oct 2018 02:47:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8321235#M24652</guid>
      <dc:creator>JanetDavidson</dc:creator>
      <dc:date>2018-10-09T02:47:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to catch  Save/Quit Document?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8321676#M24653</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like the Document.BeginDocumentClose event fires after the database have been saved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can try handling the Database.BeginSave event and check if the current command is "CLOSE".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;    public class Initialization : IExtensionApplication
    {
        public void Initialize()
        {
            var docs = Application.DocumentManager;
            foreach (Document doc in docs)
            {
                doc.Database.BeginSave += Database_BeginSave;
            }
            docs.DocumentCreated += Docs_DocumentCreated;
        }

        public void Terminate()
        { }

        private void Docs_DocumentCreated(object sender, DocumentCollectionEventArgs e)
        {
            e.Document.Database.BeginSave += Database_BeginSave;
        }

        private void Database_BeginSave(object sender, DatabaseIOEventArgs e)
        {
            var db = (Database)sender;
            var doc = Application.DocumentManager.GetDocument(db);
            if (doc.CommandInProgress == "CLOSE")
            {
                using (var tr = db.TransactionManager.StartOpenCloseTransaction())
                {
                    var ms = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite);
                    var line = new Line(Point3d.Origin, new Point3d(1000.0, 1000.0, 0.0));
                    ms.AppendEntity(line);
                    tr.AddNewlyCreatedDBObject(line, true);
                    tr.Commit();
                }
            }
        }
    } &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 08:31:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-catch-save-quit-document/m-p/8321676#M24653</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-10-09T08:31:01Z</dc:date>
    </item>
  </channel>
</rss>

