AutoCAD Map 3D Developer
Welcome to Autodesk’s AutoCAD Map 3D Developer Forums. Share your knowledge, ask questions, and explore popular AutoCAD Map 3D Developer topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getting Object Data - Unhandled Exception

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

Getting Object Data - Unhandled Exception

After below method is executed.

I am getting Unhandled Exception during closing the AutoCAD Map3D 2012

 

  <CommandMethod("Object_Read")> _
Public Sub Object_Read()
        Try
            Dim id As ObjectId
            Dim doc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim trans As Transaction = db.TransactionManager.StartTransaction()

            Dim odTable As Autodesk.Gis.Map.ObjectData.Table
            Dim odTables As Autodesk.Gis.Map.ObjectData.Tables
            odTables = HostMapApplicationServices.Application.ActiveProject.ODTables

            Dim ed As Autodesk.AutoCAD.EditorInput.Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
            Using docloc As DocumentLock = doc.LockDocument
                Dim prompt_result As PromptEntityResult = ed.GetEntity(vbCrLf + "Select the object...")
                id = prompt_result.ObjectId
                Dim dbObj As DBObject = trans.GetObject(id, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite)
                odTable = odTables.Item("DBLINK")
                Dim odrecords As ObjectData.Records = odTable.GetObjectTableRecords(Convert.ToUInt32(0), id, Constants.OpenMode.OpenForWrite, True)
                Dim odRecord As ObjectData.Record = odrecords(0)
                'Dim mapVal As Autodesk.Gis.Map.Utilities.MapValue
                MsgBox(odRecord.Count())
                MsgBox(odRecord.Item(0).StrValue)
                'odrecords.UpdateRecord(odRecord)
            End Using
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

 

2 REPLIES 2
Message 2 of 3
Alfred.NESWADBA
in reply to: Anonymous

Hi,

 

first: I haven't tried your code, but what I know is that the Map3D-API is very sensitiv if objects are not disposed. So try to use .Dispose for every object from the Map3D-API that has this method (ODTable, ODRecord, ...).

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 3
norman.yuan
in reply to: Anonymous

Although, as the other reply from alfred suggested, not calling Dispose() might be the problem, but calling Dispose() or not on the object ODTable, ODRecord is a very complicated issue and, IMO, possibly is not the source of the error you get, because in my projects dealing with ODTable/ODRecord sometimes I did call Dispose() or used using{} block, sometimes I did not, but they seemed OK.

 

However, one bad code practice in your code is obvious: you started a transaction and open ODRecords for write, and you did not commit() or abort() the transaction, not mention not to Dispose() it. This might be the source of the error.

 

BTW, since your commandmethod does not have a commandflag set, so the command runs in the document context, there is no need to lock the document (well, there is no harm to do so, I guess). I'd suggest you try to put the transaction in the place where the Using doclock As.... is, and make sure you call Transaction.Commit() before End Using.

 

Yes, AutoCAD Map .NET API is strange/sensitive as alfred said. I have a project since AcadMap2006 that also caused exceptions when AutoCAD Map shut down, which is harmless do the drafting, but annoying. I tried many time to debug it and never found the cause of it. It remained in AcadMap2007/8/9. I did not used acadMap2010/11. We recently jumped to AcadMap2012, whithout any change other than update the references to acdbmgd/acmgd/ManagedMapApi dlls, the AutoCAD shutting down errors are gone.

Norman Yuan

Drive CAD With Code

EESignature

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

Post to forums  

Autodesk Design & Make Report

”Boost