Read ACAD_OC dictionary and get Name and Handle

Read ACAD_OC dictionary and get Name and Handle

Sgear
Advocate Advocate
2,453 Views
5 Replies
Message 1 of 6

Read ACAD_OC dictionary and get Name and Handle

Sgear
Advocate
Advocate

 

Hi

I use Object Classification to draw Object

in test_table how can I get Object name and hande

Polyline 1 4048803
Polyline 5 4048809

 

 

Sampe I use to get the name

 

 

         Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor

            Using trans As Transaction = db.TransactionManager.StartTransaction()
                Dim NOD As DBDictionary = trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead, False)
                Dim DBDict As DBDictionary
                Try
                    DBDict = trans.GetObject(NOD.GetAt("ACAD_OC"), OpenMode.ForRead)
                Catch ex As Autodesk.AutoCAD.Runtime.Exception
                    MsgBox(ex.Message)
                    Exit Sub
                End Try

                Dim DictEnum As DbDictionaryEnumerator = DBDict.GetEnumerator()

                While DictEnum.MoveNext
                    Dim PageDict As DBDictionary = DirectCast(trans.GetObject(DictEnum.Value, OpenMode.ForRead), DBDictionary)
                    For Each eDict As DictionaryEntry In PageDict

                        ed.WriteMessage(vbLf & eDict.Key.ToString & " " & eDict.Value.ToString)

                    Next
                End While

            End Using

 

 

table.png

 

0 Likes
Accepted solutions (1)
2,454 Views
5 Replies
Replies (5)
Message 2 of 6

BKSpurgeon
Collaborator
Collaborator

Shouldn't each eDict.Value basically be a DBObject?

 

In that case, I'm not familiar with how VB.net handles casting. But you could get the DBObject after casting eDict.Value appropriately and simply use the handle property to get the handle.

 

e.g. DBObject obj

obj.Handle  should give you the handle.

 

As for getting the type of Object you can use the ObjectId property of the DBObject to get you the object id, and from there, you can get the Object class.

 

so you have something like this

 

DBObject obj  =  cast the dictionary value appropriately

 

then:

 

ObjectId id =  obj.Objectid 

 

Now you have the Objectid.

 

Simply use the ObjectClass property of the object id object and you get the RXClass of the relevant object e.g. Polyline etc or otherwise.

 

 

hope that makes sense. i might have made a mistake so please do verify results for yourself.

0 Likes
Message 3 of 6

Sgear
Advocate
Advocate

 

I am not programmer just someone who is trying 🙂
Not sure if eDict.Value id DBObject or just record in DictionaryEntry what keep info about Object

I try this no luck getting connection from the DictionaryEntry to the Object in the drawing

 

 

 

                     Dim tr As Transaction = doc.TransactionManager.StartTransaction
                        Dim obj As DBObject = tr.GetObject(eDict.Value, OpenMode.ForWrite)

                        ed.WriteMessage("Test " & obj.ObjectId.ToString & " " & obj.ObjectId.Handle.ToString)

                        tr.Dispose()

 

0 Likes
Message 4 of 6

Norman_Yuan
Mentor
Mentor
Accepted solution

In a drawing database' NamedDictionary, AutoCAD expects all the child-entries directly beneath it to be a DBDictionary. However, when you go one level down on every of these DBDictionaries, their DBDictionaryEntry's value (ObjecId) could point to ANY type of DBObject, usually they are XRecords with the data being an array of TypedValues, but could be something else, such as DBDictionary again...

 

So, wanting to intercept DBDictionary not created by your own custom code, it is in general not a good idea/good practice, because you have to guess the undocumented data. For example, in your case, if an entry in the "ACAD_OC" dictionary is a XRecord with a big array of TypedValue, how do you know the meaning of each TypedValue for sure (because the TypedValue array only tells you each one's data type and data value, which can be used for any purpose)? If you are not certain, then your code that tries to use the data for your own app would be not reliable at all.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 6

BKSpurgeon
Collaborator
Collaborator

please refer to Norman's statements.

 

rgds

 

0 Likes
Message 6 of 6

Sgear
Advocate
Advocate

Thanks  🙂

0 Likes