Question about traversing xrecord data

Question about traversing xrecord data

Anonymous
Not applicable
748 Views
2 Replies
Message 1 of 3

Question about traversing xrecord data

Anonymous
Not applicable
Spoiler
Spoiler
Hello everybody!
Spoiler
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.".
Spoiler
Does anyone have idea about this?

I will be grateful to you, if you could write some code about how to solve this.

Best regards,

Spoiler
Here is my code.
Spoiler
if (entity != null)
                        {
                            
                            #region XRecord
                            if (entity.ExtensionDictionary != null && 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: "+ tv.Value);
                                    n++;
                                }
                                rb.Dispose();
                            }
                            #endregion


                        }

 

 

0 Likes
749 Views
2 Replies
Replies (2)
Message 2 of 3

Balaji_Ram
Alumni
Alumni

Hi,

 

Sorry for the delay.

 

I do not see any obvious issues with your code and it worked ok in AutoCAD 2014.

I tried it on an entity which had its extension dictionary created using the ArxDbg as shown in the attached screenshot.

 

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.

 

If you can provide a non-confidential sample drawing that gives you the error message, I can look into it.

 

Regards,

 

Balaji

 

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 3

Anonymous
Not applicable

THX!

 

I'll test whether it's a sub dictionaries.

 

Attached please find my test dwg file.

0 Likes