I'm new to .net and was attempting to attach xdata to an entity. I dont seem to be able to get a value into the result buffer.
Any assitance would be appreciated.
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.ApplicationServices
Class XData
Public Shared Function AddXData(ByVal ObjId As ObjectId, ByVal Appname As String, ByVal DataVal As String, ByVal dataVal1 As String) As Boolean
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim myT As Transaction = db.TransactionManager.StartTransaction()
Try
Dim obj As DBObject = myT.GetObject(ObjId, OpenMode.ForWrite)
AddRegAppTableRecord(Appname)
Dim rb As New ResultBuffer(New TypedValue(1001, Appname), New TypedValue(1000, DataVal), New TypedValue(1000, dataVal1))
obj.XData = rb
myT.Commit()
Catch ex As Exception
MsgBox(vbCrLf & ex.Message & vbCrLf)
Finally
myT.Dispose()
End Try
End Function
Public Shared Sub AddRegAppTableRecord(ByVal regAppName As String)
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim myT As Transaction = db.TransactionManager.StartTransaction()
Try
Dim rat As RegAppTable = CType(myT.GetObject(db.RegAppTableId, OpenMode.ForRead, False), RegAppTable)
If Not rat.Has(regAppName) Then
rat.UpgradeOpen()
Dim ratr As New RegAppTableRecord
ratr.Name = regAppName
rat.Add(ratr)
myT.AddNewlyCreatedDBObject(ratr, True)
End If
myT.Commit()
Catch ex As Exception
MsgBox(vbCrLf & ex.Message & vbCrLf)
Finally
myT.Dispose()
End Try
End Sub
End Class
edited by Daniel, added code tags