Issue
How do I delete Xdata that is attached to an entity?
Solution
The following sample code demonstrates how to delete an Entity's Extended Entity data.
VBA:
Sub test()
Dim obj As Object
Dim xtype(0) As Integer
Dim xvalue(0) As Variant
xtype(0) = 1001
'MyApp is assumed to be the registered application.
xvalue(0) = "MyApp"
'select an entity
ThisDrawing.Utility.GetEntity obj, pt, "Pick: "
' remove the xdata
obj.SetXData xtype, xvalue
End Sub
C#:
[CommandMethod("REMXDATA")]
static public void RemoveXdata()
{
Document doc =
Autodesk.AutoCAD.ApplicationServices.Application.
DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Transaction tr =
db.TransactionManager.StartTransaction();
using (tr)
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
try
{
// Prompt the user to select an entity
PromptEntityResult ers;
ers = ed.GetEntity("Pick entity ");
// Open the selected entity
Entity ent =
(Entity)tr.GetObject(ers.ObjectId,
OpenMode.ForWrite);
// This call would ensure that the Xdata of the entity
// associated with ADSK application name only would be removed
ent.XData = new ResultBuffer(
new TypedValue(1001, "ADSK"));
tr.Commit();
}
catch (System.Exception ex)
{
ed.WriteMessage("Exception while removing Xdata: "
+ ex.Message);
tr.Abort();
}
finally
{
}
}
}

Leave a Reply