<?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 Question about traversing xrecord data in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/question-about-traversing-xrecord-data/m-p/4643149#M46867</link>
    <description>&lt;LI-SPOILER&gt;&lt;LI-SPOILER&gt;Hello everybody!&lt;/LI-SPOILER&gt; &lt;LI-SPOILER&gt;I'm trying to traverse xrecord data of each entity, but I got an error: "Operation is not valid due to the current state of the object.".&lt;/LI-SPOILER&gt; &lt;LI-SPOILER&gt;Does anyone have idea about this?&lt;P&gt;I will be grateful to you, if you could write some code about how to solve this.&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;/LI-SPOILER&gt;&lt;LI-SPOILER&gt;Here is my code. &lt;/LI-SPOILER&gt; &lt;LI-SPOILER&gt;&lt;PRE&gt;if (entity != null)
                        {
                            
                            #region XRecord
                            if (entity.ExtensionDictionary != null &amp;amp;&amp;amp; entity.ExtensionDictionary.IsValid)
                            {
                                DBDictionary extensionDic = transaction.GetObject(entity.ExtensionDictionary, OpenMode.ForRead) as DBDictionary;

                                ObjectId rb1 = extensionDic.GetField();

                                DbDictionaryEnumerator iterator = extensionDic.GetEnumerator();
                                while (iterator.MoveNext())
                                {
                                    DBDictionaryEntry dbdEntry = iterator.Current;
                                    Xrecord xr = transaction.GetObject(dbdEntry.Value, OpenMode.ForRead) as Xrecord;

                                    
                                    if (xr != null)
                                    {
                                        try
                                        {
                                            ResultBuffer xrrb = xr.Data;
                                            if (xrrb != null)
                                            {
                                                datalog.WriteNormalLog("找到XRECORD！");
                                                int n = 1;
                                                foreach (TypedValue tv in xrrb)
                                                {
                                                    datalog.WriteNormalLog("the " + n + "th xrecord: " + tv.Value);
                                                    n++;
                                                }
                                                xrrb.Dispose();
                                            }
                                        }
                                        catch (System.Exception ex)
                                        {
                                            ex = null;
                                        }
                                    }
                                }
                            }
                            #endregion

                            #region XData
                            ResultBuffer rb = entity.XData;
                            if (rb != null)
                            {
                                int n = 1;
                                foreach (TypedValue tv in rb)
                                {
                                    datalog.WriteNormalLog("the " + n + "th xdata&amp;amp;colon; "+ tv.Value);
                                    n++;
                                }
                                rb.Dispose();
                            }
                            #endregion


                        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI-SPOILER&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI-SPOILER&gt;</description>
    <pubDate>Fri, 22 Nov 2013 06:40:29 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2013-11-22T06:40:29Z</dc:date>
    <item>
      <title>Question about traversing xrecord data</title>
      <link>https://forums.autodesk.com/t5/net-forum/question-about-traversing-xrecord-data/m-p/4643149#M46867</link>
      <description>&lt;LI-SPOILER&gt;&lt;LI-SPOILER&gt;Hello everybody!&lt;/LI-SPOILER&gt; &lt;LI-SPOILER&gt;I'm trying to traverse xrecord data of each entity, but I got an error: "Operation is not valid due to the current state of the object.".&lt;/LI-SPOILER&gt; &lt;LI-SPOILER&gt;Does anyone have idea about this?&lt;P&gt;I will be grateful to you, if you could write some code about how to solve this.&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;/LI-SPOILER&gt;&lt;LI-SPOILER&gt;Here is my code. &lt;/LI-SPOILER&gt; &lt;LI-SPOILER&gt;&lt;PRE&gt;if (entity != null)
                        {
                            
                            #region XRecord
                            if (entity.ExtensionDictionary != null &amp;amp;&amp;amp; entity.ExtensionDictionary.IsValid)
                            {
                                DBDictionary extensionDic = transaction.GetObject(entity.ExtensionDictionary, OpenMode.ForRead) as DBDictionary;

                                ObjectId rb1 = extensionDic.GetField();

                                DbDictionaryEnumerator iterator = extensionDic.GetEnumerator();
                                while (iterator.MoveNext())
                                {
                                    DBDictionaryEntry dbdEntry = iterator.Current;
                                    Xrecord xr = transaction.GetObject(dbdEntry.Value, OpenMode.ForRead) as Xrecord;

                                    
                                    if (xr != null)
                                    {
                                        try
                                        {
                                            ResultBuffer xrrb = xr.Data;
                                            if (xrrb != null)
                                            {
                                                datalog.WriteNormalLog("找到XRECORD！");
                                                int n = 1;
                                                foreach (TypedValue tv in xrrb)
                                                {
                                                    datalog.WriteNormalLog("the " + n + "th xrecord: " + tv.Value);
                                                    n++;
                                                }
                                                xrrb.Dispose();
                                            }
                                        }
                                        catch (System.Exception ex)
                                        {
                                            ex = null;
                                        }
                                    }
                                }
                            }
                            #endregion

                            #region XData
                            ResultBuffer rb = entity.XData;
                            if (rb != null)
                            {
                                int n = 1;
                                foreach (TypedValue tv in rb)
                                {
                                    datalog.WriteNormalLog("the " + n + "th xdata&amp;amp;colon; "+ tv.Value);
                                    n++;
                                }
                                rb.Dispose();
                            }
                            #endregion


                        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI-SPOILER&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI-SPOILER&gt;</description>
      <pubDate>Fri, 22 Nov 2013 06:40:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/question-about-traversing-xrecord-data/m-p/4643149#M46867</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-11-22T06:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: Question about traversing xrecord data</title>
      <link>https://forums.autodesk.com/t5/net-forum/question-about-traversing-xrecord-data/m-p/4711545#M46868</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry for the delay.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 14px; line-height: 15px;"&gt;I do not see any obvious issues with your code and it worked ok in AutoCAD 2014.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 14px; line-height: 15px;"&gt;I tried it on an entity which had its extension dictionary created using the ArxDbg as shown in the attached screenshot.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, you cannot say for sure that the "dbdEntry.Value" will always be an ObjectId to an Xrecord. It could also be other DBDictionary which are sub dictionaries. So you may need to test if that is the case and if so, get its enumerator to enumerate further.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can provide a non-confidential sample drawing that gives you the error message, I can look into it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Balaji&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Dec 2013 10:11:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/question-about-traversing-xrecord-data/m-p/4711545#M46868</guid>
      <dc:creator>Balaji_Ram</dc:creator>
      <dc:date>2013-12-23T10:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: Question about traversing xrecord data</title>
      <link>https://forums.autodesk.com/t5/net-forum/question-about-traversing-xrecord-data/m-p/4713079#M46869</link>
      <description>&lt;P&gt;THX！&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll test whether it's a sub dictionaries.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached please find my test dwg file.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2013 07:54:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/question-about-traversing-xrecord-data/m-p/4713079#M46869</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-12-24T07:54:53Z</dc:date>
    </item>
  </channel>
</rss>

