Does it have Object Data? vb.net

Does it have Object Data? vb.net

Anonymous
Not applicable
3,700 Views
15 Replies
Message 1 of 16

Does it have Object Data? vb.net

Anonymous
Not applicable

i am trying to read the Object data records.  i can see the object data table and definitions and field names, but cannot seem to get to the value of each field.  What am i missing?

 

Dim

ed AsEditor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor

 

Dim pe AsNewPromptEntityOptions("Select Object..")

 

Dim pr AsPromptEntityResult= ed.GetEntity(pe)

 

If pr.Status = PromptStatus.OK ThenUsing trans AsTransaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()

 

Dim ent AsEntity = trans.GetObject(pr.objectid, OpenMode.ForRead)

 

Dim myTables As Autodesk.Gis.Map.ObjectData.Tables = Autodesk.Gis.Map.HostMapApplicationServices.Application.ActiveProject.ODTables

 

Dim myRec As Autodesk.Gis.Map.ObjectData.Records = myTables.GetObjectRecords(0, ent.ObjectId, Autodesk.Gis.Map.Constants.OpenMode.OpenForRead, True)

 

Dim myFieldDef As Autodesk.Gis.Map.ObjectData.FieldDefinitions' Dim FieldDef As Autodesk.Gis.Map.ObjectData.FieldDefinitionForEach rec As Autodesk.Gis.Map.ObjectData.RecordInmyRec

 

Dim table As Autodesk.Gis.Map.ObjectData.Table= myTables(rec.TableName.ToString)

myFieldDef = table.FieldDefinitions

Dim i AsIntegerWhilei < myFieldDef.Count

MsgBox(myFieldDef.Item(i).Name)

i = i + 1

EndWhileNextEndUsingEndIf

0 Likes
3,701 Views
15 Replies
Replies (15)
Message 2 of 16

Anonymous
Not applicable

forgot to say 2012.

0 Likes
Message 3 of 16

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

Dim i As Integer = 0
While i < myFieldDef.Count
  'you first have to check the datatype of the column
  'then you can do one of these statements (or more like boolean ...)
  debug.print rec(i).Int32Value.ToString
  debug.print rec(i).DoubleValue.ToString
  debug.print rec(i).StrValue
  MsgBox(myFieldDef.Item(i).Name)
  i = i + 1
EndWhile

 HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 4 of 16

Anonymous
Not applicable

Thank you that was it.

 

0 Likes
Message 5 of 16

Anonymous
Not applicable

 

please help

I have gone through

http://wikihelp.autodesk.com/AutoCAD_Map_3D/enu/2012/Help/0000-Map_3D_O0/0009-Object_D9/0010-Introdu...

for help on extracting ObjData from  an object and it is over my head.

 

I have created referance to ManagedMapApi.dll

I have Imports Autodesk.Gis.Map.ObjectData.

 

now what do I need to do to extract OD from my objects.

Dim activeProject AsProject.ProjectModel = mapApp.ActiveProject
Dim table As ObjectData.Table = tableList("table1")

 

0 Likes
Message 6 of 16

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

why not continueing >>>here<<<?

 

The thread-title says "Does it have Object Data" ==> is that also your problem? Or do you have another one?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 7 of 16

Anonymous
Not applicable

Hey Alfread...looks like you are burning the midnight oil as well.

anyway when I use

 

Dim fieldDefs AsAutodesk.Gis.Map.ObjectData.FieldDefinition = table.FieldDefinitions

 

Dim recs As ObjectData.Records

recs = table.GetObjectTableRecords(0, objId, Constants.OpenMode.OpenForRead,True)

 

 from the sample,

I get a bunch of errors.

Error 1 'table' is ambiguous, imported from the namespaces or types 'Autodesk.Gis.Map.ObjectData, ADOX, Autodesk.AutoCAD.DatabaseServices'.

Error 2 Type 'ObjectData.Records' is not defined.

Error 3 'table' is ambiguous, imported from the namespaces or types 'Autodesk.Gis.Map.ObjectData, ADOX, Autodesk.AutoCAD.DatabaseServices'.

Error 4 'OpenMode' is not a member of 'Microsoft.VisualBasic.Constants'. 

 

besides all I have is a selection set and just one table.

All I want to do is get the object data of an object, and not all the objects in the selection may have object data.

0 Likes
Message 8 of 16

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> is ambiguous, imported from the namespaces or types

>>     'Autodesk.Gis.Map.ObjectData,

>>     ADOX,

>>     Autodesk.AutoCAD.DatabaseServices'

that message means you have 3 namespaces having an item "table", so the compiler does not know how to do with them.

Either you be more careful on top of your code-file with the number of "import"-statements or you write the full namespace-part to these lines.

 

And every time you get something like "not a member of" you also can try to use the full namespace for that object (or this enumeration).

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 9 of 16

Anonymous
Not applicable

Thank for your patients, I am still getting my feet wet with vb.net

Bottom line, specifically what do I need to do to get this sample code to work.

 

After that, I can step through the debugger to see exactly how it works.

0 Likes
Message 10 of 16

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

is it just a sample solution you are currently working (so you can upload your sources/projects/solution-files) or can't you upload it?

If first ... would be much easier to describe what to change 😉

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 11 of 16

Anonymous
Not applicable

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 Vb.net project folder.

 

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

 

0 Likes
Message 12 of 16

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

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. 😉

 

Good luck, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 13 of 16

Anonymous
Not applicable

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

0 Likes
Message 14 of 16

Anonymous
Not applicable

 

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
                Try
                    '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
                                                ed.WriteMessage(val.StrValue)
                                            Case Constants.DataType.Integer
                                                ed.WriteMessage(val.Int32Value.ToString)
                                            Case Constants.DataType.Point
                                                ed.WriteMessage("point")
                                            Case Constants.DataType.Real
                                                ed.WriteMessage(val.DoubleValue.ToString)
                                            Case Else
                                                ed.WriteMessage("undefined")
                                        End Select
                                    Next
                                Next
                            End If
                            recs.Dispose()

                        End If

                    Next
                    myT.Commit()
                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

 

cheers

Message 15 of 16

Alfred.NESWADBA
Consultant
Consultant

Hi,

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

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

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 16 of 16

roskirko
Collaborator
Collaborator

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.

Geographic Information Systems
Fanshawe College
0 Likes