<?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: store custom data in drawing in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/store-custom-data-in-drawing/m-p/2880912#M62298</link>
    <description>&lt;P&gt;I came across these articles, but that property only stores data for one session, i need them to be persistent.&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jan 2011 06:36:27 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2011-01-14T06:36:27Z</dc:date>
    <item>
      <title>store custom data in drawing</title>
      <link>https://forums.autodesk.com/t5/net-forum/store-custom-data-in-drawing/m-p/2879738#M62295</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;when I need to store some data in the drawing, I am usually using DBDictionary for that. But what is the way to store custom class object?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2011 14:59:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/store-custom-data-in-drawing/m-p/2879738#M62295</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-01-13T14:59:22Z</dc:date>
    </item>
    <item>
      <title>Re: store custom data in drawing</title>
      <link>https://forums.autodesk.com/t5/net-forum/store-custom-data-in-drawing/m-p/2880196#M62296</link>
      <description>&lt;P&gt;Besides using DBDictonary, you can also look into Autodesk.AutoCAD.ApplicationServices.Document.UserData property, which is an HashTable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kean had a 2-part article on this long time ago:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A target="_blank" href="http://through-the-interface.typepad.com/through_the_interface/2006/10/perdocument_dat_1.html" rel="nofollow"&gt;http://through-the-interface.typepad.com/through_the_interface/2006/10/perdocument_dat_1.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A target="_blank" href="http://through-the-interface.typepad.com/through_the_interface/2006/10/perdocument_dat_2.html" rel="nofollow"&gt;http://through-the-interface.typepad.com/through_the_interface/2006/10/perdocument_dat_2.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2011 18:33:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/store-custom-data-in-drawing/m-p/2880196#M62296</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2011-01-13T18:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: store custom data in drawing</title>
      <link>https://forums.autodesk.com/t5/net-forum/store-custom-data-in-drawing/m-p/2880626#M62297</link>
      <description>&lt;P&gt;I know its possible because we have a program inhouse that does store data in the file not more than a few KB extra.&amp;nbsp; Though I have no clue how its done, new to this.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2011 22:29:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/store-custom-data-in-drawing/m-p/2880626#M62297</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-01-13T22:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: store custom data in drawing</title>
      <link>https://forums.autodesk.com/t5/net-forum/store-custom-data-in-drawing/m-p/2880912#M62298</link>
      <description>&lt;P&gt;I came across these articles, but that property only stores data for one session, i need them to be persistent.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2011 06:36:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/store-custom-data-in-drawing/m-p/2880912#M62298</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-01-14T06:36:27Z</dc:date>
    </item>
    <item>
      <title>Re: store custom data in drawing</title>
      <link>https://forums.autodesk.com/t5/net-forum/store-custom-data-in-drawing/m-p/2881174#M62299</link>
      <description>&lt;PRE&gt;&lt;P&gt;I don't know what kind of data you want to store.&lt;/P&gt;&lt;P&gt;But please look at my example. With this function i create a new drawing and add an xrecord with my specified data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/PRE&gt;&lt;PRE&gt;[CommandMethod("NewDoc")]
        public void NewDoc()
        {
            Database acDbNewDoc = new Database();
            
            // get the editor object
            Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;

            using (Transaction tr = acDbNewDoc.TransactionManager.StartTransaction())
            {
                try
                {
                    // open the NOD for read
                    DBDictionary nod = tr.GetObject(acDbNewDoc.NamedObjectsDictionaryId, OpenMode.ForRead) as DBDictionary;
                    try
                    {
                        // check to see if our entry is in there, excpetion will be thrown if not so process that
                        // condition in the catch
                        ObjectId entryId = nod.GetAt(ACMEDATA);

                        // if we are here, then all is ok
                        // print the data
                        //ed.WriteMessage("This entity already has data...");
                        // ok extract the xrecord
                        Xrecord myXrecord = default(Xrecord);
                        // read it from the NOD dictionary
                        myXrecord = tr.GetObject(entryId, OpenMode.ForRead) as Xrecord;

                        // now print out the values
                        // Get data from Xrecord
                        ResultBuffer resBuf = myXrecord.Data;
                        TypedValue[] resbufvalue = resBuf.AsArray();
                        acadApp.ShowAlertDialog(string.Format("{0}, {1}, {2}", resbufvalue[0].Value, resbufvalue[1].Value, resbufvalue[2].Value));
                    }
                    catch
                    {
                        // upgrade to write status
                        nod.UpgradeOpen();

                        // create a new XRecord
                        Xrecord myXrecord = new Xrecord();
                        // create the resbuf list
                        ResultBuffer data = new ResultBuffer(new TypedValue((int)DxfCode.Text, "ACMEDATA1"),
                                                             new TypedValue((int)DxfCode.Text, "ACMEDATA2"),
                                                             new TypedValue((int)DxfCode.Text, "ACMEDATA3"));
                        // now add it to the xrecord
                        myXrecord.Data = data;

                        // create the entry
                        nod.SetAt(_dictionaryName, myXrecord);
                        // tell the transaction about the newly created xrecord
                        tr.AddNewlyCreatedDBObject(myXrecord, true);
                    }
                    // all ok, commit it
                    tr.Commit();
                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    // a problem occurred, lets print it
                    ed.WriteMessage("a problem occurred because " + ex.Message);
                }
                finally
                {
                    // whatever happens we must dispose the transaction
                }
                // Save the document
                acDbNewDoc.SaveAs(@"c:\temp\XrecDWG.dwg", DwgVersion.Current);
            }
        }

        public void ReadDocData(object sender, DocumentCollectionEventArgs e)
        {
            Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;
            using (Transaction tr = ed.Document.Database.TransactionManager.StartTransaction())
            {
                try
                {
                    // open the NOD for read
                    DBDictionary nod = tr.GetObject(ed.Document.Database.NamedObjectsDictionaryId, OpenMode.ForRead) as DBDictionary;

                    // check to see if our entry is in there, excpetion will be thrown if not so process that
                    // condition in the catch
                    ObjectId entryId = nod.GetAt("ACMEDATA");

                    // if we are here, then all is ok
                    // print the data
                    // ok extract the xrecord
                    Xrecord myXrecord = default(Xrecord);
                    // read it from the NOD dictionary
                    myXrecord = tr.GetObject(entryId, OpenMode.ForRead) as Xrecord;

                    // now print out the values
                    // Get data from Xrecord
                    ResultBuffer resBuf = myXrecord.Data;
                    TypedValue[] resbufvalue = resBuf.AsArray();

                    ed.WriteMessage(string.Format("\n{0}, {1}, {2}", resbufvalue[0].Value, resbufvalue[1].Value, resbufvalue[2].Value));
                }
                catch
                {
                    ed.WriteMessage("\nThis is drawing doesn't have ACME data");
                }
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2011 14:06:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/store-custom-data-in-drawing/m-p/2881174#M62299</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-01-14T14:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: store custom data in drawing</title>
      <link>https://forums.autodesk.com/t5/net-forum/store-custom-data-in-drawing/m-p/2882810#M62300</link>
      <description>&lt;P&gt;yeah, that's what i use, when i want to store texts and numbers, but i have a class containing several properties, including ArrayList and that ArrayList is made of custom objects too&lt;/P&gt;&lt;P&gt;I tried serialization, but the problem is, that AutoCAD classes like Point3d are not serializable.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jan 2011 06:26:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/store-custom-data-in-drawing/m-p/2882810#M62300</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-01-17T06:26:57Z</dc:date>
    </item>
  </channel>
</rss>

