Why not just use GetXDataForApplication() to avoid
having to deal with all xdata ?
Also, .XData = should not replace
any existing xdata for applications whose ids are
not in the resultbuffer list, you don't have to bother
mucking around with everyone's xdata.
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com
wrote in message news:5546639@discussion.autodesk.com...
I have found that code can corrupt the xdata for the entity.
The following code seems ok.
Public Sub RemoveXData(ByVal objEntId As ObjectId, ByVal strAppName As String)
Dim objDB As Database = HostApplicationServices.WorkingDatabase
Dim objTrans As Transaction = objDB.TransactionManager.StartTransaction
Dim objEnt As Entity = CType(objTrans.GetObject(objEntId, DatabaseServices.OpenMode.ForWrite, False), Entity)
If objEnt.XData <> Nothing Then
Dim blnRecord As Boolean = True
Dim blnFound As Boolean = False
Dim objResBuf As ResultBuffer = objEnt.XData
Dim objNewResBuf As ResultBuffer = New ResultBuffer
Dim objTypedVal As TypedValue
For Each objTypedVal In objResBuf
If objTypedVal.TypeCode = 1001 Then
If CType(objTypedVal.Value, String) = strAppName Then
blnRecord = False
blnFound = True
Else
blnRecord = True
End If
End If
If blnRecord = True Then objNewResBuf.Add(objTypedVal)
Next objTypedVal
If blnFound = True Then objNewResBuf.Add(New TypedValue(1001, strAppName))
objEnt.XData = objNewResBuf
End If
objTrans.Commit()
objTrans.Dispose()
End Sub