<?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: Write data to the NOD before document closes? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/write-data-to-the-nod-before-document-closes/m-p/10951746#M13631</link>
    <description>that appears to have worked, thank you Sir!</description>
    <pubDate>Tue, 15 Feb 2022 15:18:27 GMT</pubDate>
    <dc:creator>nshupeFMPE3</dc:creator>
    <dc:date>2022-02-15T15:18:27Z</dc:date>
    <item>
      <title>Write data to the NOD before document closes?</title>
      <link>https://forums.autodesk.com/t5/net-forum/write-data-to-the-nod-before-document-closes/m-p/10950196#M13629</link>
      <description>&lt;P&gt;I'm trying to find what event would be the best to react to in in order to write data to the NOD before the document closes. I've tried reacting to&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Application.DocumentManager.DocumentDestroyed += new DocumentDestroyedEventHandler(docColDocDestroyed)&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;but get an error when trying to create a transaction.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;And when I try to react to&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Document.BeginDocumentClose&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get an eLockedViolation. The violation comes from an external assembly that I cant change, and I need the assembly for backwards compatibility (I'm only doing this part for backwards compatibility.)&lt;BR /&gt;&lt;BR /&gt;Any help would be greatly appreciated!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Feb 2022 22:45:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/write-data-to-the-nod-before-document-closes/m-p/10950196#M13629</guid>
      <dc:creator>nshupeFMPE3</dc:creator>
      <dc:date>2022-02-14T22:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: Write data to the NOD before document closes?</title>
      <link>https://forums.autodesk.com/t5/net-forum/write-data-to-the-nod-before-document-closes/m-p/10950719#M13630</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Try to handle the &lt;A href="https://help.autodesk.com/view/OARX/2022/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_ApplicationServices_DocumentCollection_DocumentToBeDestroyed" target="_blank" rel="noopener"&gt;DocumentToBeDestroyed&lt;/A&gt; event and, in the event handler, use an OpenCloseTransaction instead of a standard Transaction.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Feb 2022 06:37:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/write-data-to-the-nod-before-document-closes/m-p/10950719#M13630</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-02-15T06:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: Write data to the NOD before document closes?</title>
      <link>https://forums.autodesk.com/t5/net-forum/write-data-to-the-nod-before-document-closes/m-p/10951746#M13631</link>
      <description>that appears to have worked, thank you Sir!</description>
      <pubDate>Tue, 15 Feb 2022 15:18:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/write-data-to-the-nod-before-document-closes/m-p/10951746#M13631</guid>
      <dc:creator>nshupeFMPE3</dc:creator>
      <dc:date>2022-02-15T15:18:27Z</dc:date>
    </item>
    <item>
      <title>Re: Write data to the NOD before document closes?</title>
      <link>https://forums.autodesk.com/t5/net-forum/write-data-to-the-nod-before-document-closes/m-p/10975882#M13632</link>
      <description>&lt;P&gt;it appears that the Transaction completes without failing, but that the changes are not saved to the NOD as the changes do not appear when opening the file again.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Feb 2022 18:33:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/write-data-to-the-nod-before-document-closes/m-p/10975882#M13632</guid>
      <dc:creator>nshupeFMPE3</dc:creator>
      <dc:date>2022-02-28T18:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: Write data to the NOD before document closes?</title>
      <link>https://forums.autodesk.com/t5/net-forum/write-data-to-the-nod-before-document-closes/m-p/10976044#M13633</link>
      <description>&lt;P&gt;You have to save the document.&lt;/P&gt;
&lt;P&gt;This works for me:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        private void Docs_DocumentToBeDestroyed(object sender, DocumentCollectionEventArgs e)
        {
            var db = e.Document.Database;
            using (var tr = db.TransactionManager.StartOpenCloseTransaction())
            {
                var nod = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead);
                DBDictionary dict;
                if (nod.Contains("FOO"))
                {
                    dict = (DBDictionary)tr.GetObject(nod.GetAt("FOO"), OpenMode.ForRead);
                }
                else
                {
                    dict = new DBDictionary();
                    nod.UpgradeOpen();
                    nod.SetAt("FOO", dict);
                    tr.AddNewlyCreatedDBObject(dict, true);
                }
                Xrecord xrec;
                if (dict.Contains("Bar"))
                {
                    xrec = (Xrecord)tr.GetObject(dict.GetAt("Bar"), OpenMode.ForWrite);
                }
                else
                {
                    xrec = new Xrecord();
                    if (!dict.IsWriteEnabled)
                        dict.UpgradeOpen();
                    dict.SetAt("Bar", xrec);
                    tr.AddNewlyCreatedDBObject(xrec, true);
                }
                xrec.Data = new ResultBuffer(new TypedValue(1, "baz"));
                tr.Commit();
            }
            dynamic acadDoc = e.Document.GetAcadDocument();
            acadDoc.Save();
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 28 Feb 2022 20:01:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/write-data-to-the-nod-before-document-closes/m-p/10976044#M13633</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-02-28T20:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Write data to the NOD before document closes?</title>
      <link>https://forums.autodesk.com/t5/net-forum/write-data-to-the-nod-before-document-closes/m-p/11412200#M13634</link>
      <description>&lt;P&gt;Does this save the document on closing regardless of whether or not the user has chosen not to?&lt;/P&gt;&lt;P&gt;Your solution here is another which doesn't. &lt;A href="https://forums.autodesk.com/t5/net/how-to-catch-save-quit-document/m-p/8321676#M60415" target="_blank" rel="noopener"&gt;https://forums.autodesk.com/t5/net/how-to-catch-save-quit-document/m-p/8321676#M60415&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2022 20:52:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/write-data-to-the-nod-before-document-closes/m-p/11412200#M13634</guid>
      <dc:creator>SRSDS</dc:creator>
      <dc:date>2022-09-09T20:52:33Z</dc:date>
    </item>
  </channel>
</rss>

