Problem with ObjectData (VB.Net)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm having a problem with ObjectData.
-- See code below for reference --
I'm calling the function attachODAndSetValue several times through a For statement (For each id in ObjectIDList).
Eventually, I alway get the following error:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
The error always refer to the following line of my code: table.AddRecord(rec, id)
Before calling attachODAndSetValue, I make sure that the ObjectID passed to the function is valid (I check if id.isValid = True).
Did some of you had this kind of problem with ObjectData? Did you find a solution?
I'm using AutoCAD MAP 3D 2010 64bits on Windows 7
Thanks
Louis
Public Function attachODAndSetValue(ByVal tableName As String, ByVal id As ObjectId, ByVal dataCol As Collection) As Integer
'tableName : ObjectData Table to attach to the Object
'id : objectId of the element to which I want to attach the ObjectData
'dataCol : data to write in the ObjectData
Dim errStatus As Integer = 0
Dim rec As Record = Nothing
Try
Dim mapApp As Autodesk.Gis.Map.MapApplication = Autodesk.Gis.Map.HostMapApplicationServices.Application
Dim activeProject As Project.ProjectModel = mapApp.ActiveProject
Dim tableList As Tables = activeProject.ODTables
If tableList.IsTableDefined(tableName) = False Then
'table does not exist, exit try
errStatus = 2
Exit Try
End If
Dim table As ObjectData.Table = tableList.Item(tableName)
'Create and Initialize the record
rec = ObjectData.Record.Create
table.InitRecord(rec)
If rec.Count = dataCol.Count Then
Dim i As Integer
For i = 0 To rec.Count - 1
'Assign the value
rec.Item(i).Assign(dataCol.Item(i + 1))
Next
Else
errStatus = 3
Exit Try
End If
table.AddRecord(rec, id) 'Program crashed here
errStatus = 0
Catch err As MapException
MessageBox.Show("Error:" & vbNewLine & err.Message & vbNewLine & vbNewLine & err.ToString)
errStatus = 1
Finally
If rec IsNot Nothing Then
rec.Dispose()
End If
End Try
Return errStatus
End Function