AutoCAD Map 3D Developer

AutoCAD Map 3D Developer

208 Posts
8 Kudos
Registered: ‎08-21-2007
Post 11 of 16

Re: Does it have Object Data?

04-24-2012 11:47 AM in reply to: Alfred.NESWADBA

I am reading a CAD drawing, creating a MDB file and writing out the data.

However, I will comment out the call to the other routines to simplify it.


The section call is TextExtractOBJData and I am passing a selection set.

the dwg file Text.dwg is in the project folder.


thanks for looking into this. Any suggestions or recommendations are welcomed.


*Expert Elite*
9,819 Posts
1,212 Kudos
Registered: ‎06-29-2007
Post 12 of 16

Re: Does it have Object Data?

04-24-2012 01:47 PM in reply to: mfernandes



I did what I could do, but some objects are unclear to me, e.g. the object "tables" you reference but never declared or assigned anything to it. That's your job.

Therefor (and for the reason I currently have 64bit running) I could not start anything as you have some ADOX-/MDB-access.


A tip for the future: use "strict on" in your project settings. It's a little bit more code to write as then late-binding is disabled by default and you have to use some TryCast or CType coding, but the code will run more stable as you see type-mismatches while code-writing and not as exceptions at customer-place. :smileywink:


Good luck, - alfred -

Ingenieur Studio HOLLAUS ...
208 Posts
8 Kudos
Registered: ‎08-21-2007
Post 13 of 16

Re: Does it have Object Data?

04-24-2012 07:21 PM in reply to: mfernandes

What you see is simply a cut and paste of the sample from the Autodesk site.

So I too do not know what the object "Table" refers too.


basically at this point all I want is a routine that I can pass an object and it returns it's object data.


thanks for helping

208 Posts
8 Kudos
Registered: ‎08-21-2007
Post 14 of 16

Re: Does it have Object Data?

04-25-2012 12:25 AM in reply to: mfernandes


EUREKA, I filnally got it !!!!

I did some more digging in the documentation  and pulled all the pieces together.


just in case some other poor sap like me needs to extract object data.

Here is the code.

References are AcDbMgd, AcMgd, managedMapApi



Imports System
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput

Imports Autodesk.Gis.Map.ObjectData
Imports Autodesk.Gis.Map

        Private Sub TestExtractOBJData(ByRef acSSet As SelectionSet)
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument()
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor

            Dim mapApp As MapApplication
            mapApp = HostMapApplicationServices.Application
            Dim activeProject As Autodesk.Gis.Map.Project.ProjectModel = mapapp.ActiveProject
            Dim tableList As Autodesk.Gis.Map.ObjectData.Tables = activeProject.ODTables
            'get specific table = "MyTable"
            Dim table As ObjectData.Table = tableList("MyTable")

            'Dim acEditor As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor

            'start a transaction
            Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = db.TransactionManager
            Dim myT As Transaction = tm.StartTransaction()

            Using myT
                    'loop through object in the selection set
                    For Each sobj As SelectedObject In acSSet
                        Dim ent As Entity = myT.GetObject(sobj.ObjectId, OpenMode.ForRead)
                        If TypeOf ent Is DBText Then
                            Dim tt As DBText = DirectCast(ent, DBText)

                            Dim fieldDefs As ObjectData.FieldDefinitions = table.FieldDefinitions
                            Dim recs As ObjectData.Records
                            recs = table.GetObjectTableRecords(0, sobj.ObjectId, Constants.OpenMode.OpenForRead, True)

                            'check if there are records for the selected table
                            If (recs.Count() > 0) Then
                                For Each rec As ObjectData.Record In recs
                                    'get object data for each record in table
                                    For i As Integer = 0 To rec.Count() - 1
                                        Dim val As Autodesk.Gis.Map.Utilities.MapValue
                                        val = rec(i)
                                        Dim fieldDef As ObjectData.FieldDefinition
                                        fieldDef = fieldDefs(i)
                                        ed.WriteMessage(vbNewLine + fieldDef.Name + ": ")
                                        Select Case val.Type
                                            Case Constants.DataType.Character
                                            Case Constants.DataType.Integer
                                            Case Constants.DataType.Point
                                            Case Constants.DataType.Real
                                            Case Else
                                        End Select
                            End If

                        End If

                Catch ex As Autodesk.AutoCAD.Runtime.Exception
                    ed.WriteMessage(vbLf & "{0}" & vbLf & "{1}", ex.Message, ex.StackTrace)
                End Try
            End Using

        End Sub

 Big thanks to alfred for spending time and patients with me



*Expert Elite*
9,819 Posts
1,212 Kudos
Registered: ‎06-29-2007
Post 15 of 16

Re: Does it have Object Data?

04-25-2012 11:58 AM in reply to: mfernandes


>> I did some more digging in the documentation and pulled all the pieces together.
That's how development works :smileywink:

Great you could solve it and that you published it here for others (not all do that)!

- alfred -

Ingenieur Studio HOLLAUS ...
12 Posts
0 Kudos
Registered: ‎03-31-2012
Post 16 of 16

Re: Does it have Object Data?

12-21-2012 06:51 AM in reply to: mfernandes

OK great. Now that it finds the Object Data I want to highlight the drawing objects (perhaps by changing the object's color) that have an empty field for their Object Data  record (i.e. the data was not entered and the field value and is now blank or empty).


Once those objects are identified on the drawing (perhaps by turning their color to RED) , the Object Data for these drawing objects can then be altered to contain a non-blank entry.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!