<?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: Save a string value in dwg file in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/save-a-string-value-in-dwg-file/m-p/8595272#M23493</link>
    <description>&lt;P&gt;Thanks for this reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But in need something different....&lt;/P&gt;
&lt;P&gt;Like variable while are already available in DWG&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;&lt;STRONG&gt;USERS1-5&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;&lt;STRONG&gt;Actually I want to save it in VB.net and want to get the same in ObjectARX c++ and vice versa&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Feb 2019 09:19:44 GMT</pubDate>
    <dc:creator>abdul.haseeb</dc:creator>
    <dc:date>2019-02-14T09:19:44Z</dc:date>
    <item>
      <title>Save a string value in dwg file</title>
      <link>https://forums.autodesk.com/t5/net-forum/save-a-string-value-in-dwg-file/m-p/8595020#M23491</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to save a string value in dwg file say "something to be saved".&lt;/P&gt;
&lt;P&gt;then when I needed I should get this value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please kindly help to get this.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 07:17:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/save-a-string-value-in-dwg-file/m-p/8595020#M23491</guid>
      <dc:creator>abdul.haseeb</dc:creator>
      <dc:date>2019-02-14T07:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: Save a string value in dwg file</title>
      <link>https://forums.autodesk.com/t5/net-forum/save-a-string-value-in-dwg-file/m-p/8595181#M23492</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use an &lt;A href="http://help.autodesk.com/view/OARX/2018/ENU/?guid=OREFNET-Autodesk_AutoCAD_DatabaseServices_Xrecord" target="_blank" rel="noopener"&gt;Xrecord&lt;/A&gt; in a &lt;A href="http://help.autodesk.com/view/OARX/2018/ENU/?guid=OREFNET-Autodesk_AutoCAD_DatabaseServices_DBDictionary" target="_blank" rel="noopener"&gt;DBDictionary&lt;/A&gt; to store the string.&lt;/P&gt;
&lt;P&gt;You'll find many example in this forum, &lt;A href="https://forums.autodesk.com/t5/net/xrecord/m-p/7784421/highlight/true#M57654" target="_blank" rel="noopener"&gt;here's one&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 08:39:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/save-a-string-value-in-dwg-file/m-p/8595181#M23492</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-02-14T08:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: Save a string value in dwg file</title>
      <link>https://forums.autodesk.com/t5/net-forum/save-a-string-value-in-dwg-file/m-p/8595272#M23493</link>
      <description>&lt;P&gt;Thanks for this reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But in need something different....&lt;/P&gt;
&lt;P&gt;Like variable while are already available in DWG&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;&lt;STRONG&gt;USERS1-5&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;&lt;STRONG&gt;Actually I want to save it in VB.net and want to get the same in ObjectARX c++ and vice versa&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 09:19:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/save-a-string-value-in-dwg-file/m-p/8595272#M23493</guid>
      <dc:creator>abdul.haseeb</dc:creator>
      <dc:date>2019-02-14T09:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: Save a string value in dwg file</title>
      <link>https://forums.autodesk.com/t5/net-forum/save-a-string-value-in-dwg-file/m-p/8595509#M23494</link>
      <description>&lt;P&gt;USERS1-5 is not saved in the drawing, this is why you have to use an Xrecord (or some Extended data attached to an unerasable object as the layer "0").&lt;/P&gt;
&lt;P&gt;Xrecords (and xdata) can be accessed by any AutoCAD programation environment (AutoLISP, COM, .NET, ObjectARX).&lt;/P&gt;
&lt;P&gt;"ABDUL_HASEED" and an Xrecord named "StringValue" which only contains one string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        public void SaveStringInCurrentDrawing(string str)
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            using (doc.LockDocument())
            using (var tr = new OpenCloseTransaction())
            {
                var nod = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead);
                DBDictionary dict;
                if (nod.Contains("ABDUL_HASEEB"))
                {
                    dict = (DBDictionary)tr.GetObject(nod.GetAt("ABDUL_HASEEB"), OpenMode.ForRead);
                }
                else
                {
                    dict = new DBDictionary();
                    nod.UpgradeOpen();
                    nod.SetAt("ABDUL_HASEEB", dict);
                    tr.AddNewlyCreatedDBObject(dict, true);
                }
                Xrecord xrec;
                if (dict.Contains("StringValue"))
                {
                    xrec = (Xrecord)tr.GetObject(dict.GetAt("StringValue"), OpenMode.ForWrite);
                }
                else
                {
                    xrec = new Xrecord();
                    if (!dict.IsWriteEnabled) tr.GetObject(dict.ObjectId, OpenMode.ForWrite);
                    dict.SetAt("StringValue", xrec);
                    tr.AddNewlyCreatedDBObject(xrec, true);
                }
                xrec.Data = new ResultBuffer(new TypedValue(1, str));
                tr.Commit();
            }
        }

        public string GetSavedStringInCurrentDrawing()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            using (doc.LockDocument())
            using (var tr = new OpenCloseTransaction())
            {
                var nod = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead);
                if (!nod.Contains("ABDUL_HASEEB"))
                    return null;
                var dict = (DBDictionary)tr.GetObject(nod.GetAt("ABDUL_HASEEB"), OpenMode.ForRead);
                if (!dict.Contains("ABDUL_HASEEB"))
                    return null;
                var xrec = (Xrecord)tr.GetObject(dict.GetAt("StringValue"), OpenMode.ForWrite);
                if (xrec.Data == null)
                    return null;
                return xrec.Data.AsArray()[0].Value.ToString();
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Feb 2019 10:57:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/save-a-string-value-in-dwg-file/m-p/8595509#M23494</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-02-14T10:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: Save a string value in dwg file</title>
      <link>https://forums.autodesk.com/t5/net-forum/save-a-string-value-in-dwg-file/m-p/8595740#M23495</link>
      <description>&lt;P&gt;you can also use custom properties:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;thisDrawing.SummaryInfo.AddCustomInfo("MyKey", "MyValue");&lt;/PRE&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;PRE&gt;string value = "";
thisDrawing.SummaryInfo.GetCustomByKey("MyKey", out value);&lt;/PRE&gt;
&lt;P&gt;thisdrawing:&lt;/P&gt;
&lt;PRE&gt;using acApp = Autodesk.AutoCAD.ApplicationServices.Application;
//...
thisDrawing = (AcadDocument)acApp.DocumentManager.MdiActiveDocument.GetAcadDocument();&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Feb 2019 12:48:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/save-a-string-value-in-dwg-file/m-p/8595740#M23495</guid>
      <dc:creator>stefan.hofer</dc:creator>
      <dc:date>2019-02-14T12:48:27Z</dc:date>
    </item>
  </channel>
</rss>

