.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Question about traversing xrecord data

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
537 Views, 2 Replies

Question about traversing xrecord data

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


                        }

 

 

2 REPLIES 2
Message 2 of 3
Balaji_Ram
in reply to: Anonymous

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

Message 3 of 3
Anonymous
in reply to: Balaji_Ram

THX!

 

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

 

Attached please find my test dwg file.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost