• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    AutoCAD Map 3D Developer

    Reply
    Distinguished Contributor
    Posts: 139
    Registered: ‎08-21-2007

    Re: Does it have Object Data? vb.net

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

     

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

     

    Please use plain text.
    *Expert Elite*
    Posts: 6,415
    Registered: ‎06-29-2007

    Re: Does it have Object Data? vb.net

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

    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. :smileywink:

     

    Good luck, - alfred -

    -------------------------------------------------------------------------
    Alfred NESWADBA
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Please use plain text.
    Distinguished Contributor
    Posts: 139
    Registered: ‎08-21-2007

    Re: Does it have Object Data? vb.net

    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

    Please use plain text.
    Distinguished Contributor
    Posts: 139
    Registered: ‎08-21-2007

    Re: Does it have Object Data? vb.net

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

    Please use plain text.
    *Expert Elite*
    Posts: 6,415
    Registered: ‎06-29-2007

    Re: Does it have Object Data? vb.net

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

    Hi,

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

    -------------------------------------------------------------------------
    Alfred NESWADBA
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Please use plain text.
    Member
    Posts: 3
    Registered: ‎03-31-2012

    Re: Does it have Object Data? vb.net

    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.

    Please use plain text.