One thing that has always been problematic with xdata is you can't delete it from an entity (with ActiveX).
Apparently there is a way with entmod (see below)
We have always been limited to vla-setxdata and vla-getxdata.
Although it is possible to delete xdata using .net
Code:
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
''' <summary>
''' Functions to delete (dispose) XData from Entities
''' </summary>
Public Class XdataDisposeClass1
''' <summary>
''' LISP Function to delete (dispose) of specific Xdata application information from an entity.
''' </summary>
''' <param name="rbfArguments"></param>
''' <returns> T for success - nil for failure </returns>
''' <remarks> LISP Syntax: (XdataDispose (entlast) "TEST") </remarks>
<LispFunction("XdataDispose")> _
Public Function XdataDelete(ByVal rbfArguments As ResultBuffer)
Try
Dim arrArguments As TypedValue() = rbfArguments.AsArray
If arrArguments.Length = 2 And _
arrArguments(0).TypeCode = LispDataType.ObjectId And _
arrArguments(1).TypeCode = LispDataType.Text Then
If Not XdataDispose(arrArguments(0).Value, _
arrArguments(1).Value.ToString.ToUpper) = Nothing Then
Return New TypedValue(LispDataType.T_atom, -1)
End If
End If
Catch exception As Exception
End Try
Return Nothing
End Function
''' <summary>
''' Comand line function to delete (dispose) of specific xdata application information.
''' </summary>
''' <remarks></remarks>
<CommandMethod("XdataDispose")> _
Public Sub XdataDispose()
Dim document As Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim editor As Editor = document.Editor
Dim promptresult As PromptResult = editor.GetString("Enter XData Application Name")
Dim strApplication As String = promptresult.StringResult.ToUpper
Dim transaction As Transaction = document.TransactionManager.StartTransaction
Try
Dim promptEntityResult As PromptEntityResult = editor.GetEntity("Select Entity")
If promptEntityResult IsNot Nothing Then
Dim entity As Entity = transaction.GetObject(promptEntityResult.ObjectId, OpenMode.ForRead)
XdataDispose(promptEntityResult.ObjectId, strApplication.ToUpper)
transaction.Commit()
End If
Catch exception As Exception
transaction.Abort()
End Try
transaction.Dispose()
End Sub
''' <summary>
''' General Function to Delete (Dispose) of a specific xdata application from an object
''' </summary>
''' <param name="oidItem"></param>
''' <param name="strApplication"></param>
''' <returns>True for Success - Nothing for Failure</returns>
Public Function XdataDispose(ByVal oidItem As ObjectId, ByVal strApplication As String)
Dim document As Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim transaction As Transaction = document.TransactionManager.StartTransaction
Try
Dim entity As Entity = transaction.GetObject(oidItem, OpenMode.ForRead)
Dim rbfXdata As ResultBuffer = entity.GetXDataForApplication(strApplication)
If rbfXdata IsNot Nothing Then
entity.UpgradeOpen()
entity.XData = New ResultBuffer(New TypedValue(1001, strApplication))
rbfXdata.Dispose()
transaction.Commit()
Return True
End If
Catch exception As Exception
transaction.Abort()
End Try
Return Nothing
End Function
End Class