.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Delete XData

3 REPLIES 3
Reply
Message 1 of 4
S.Sameith
1260 Views, 3 Replies

Delete XData

Hi,
i want to delete the Xdata of an Object.
But it doesnt work. Maybe anyone can help...
Is there maybe anotherway to Delete all Xdata in a drawing ?

static public void deltexd()
{

Document doc = Application.DocumentManager.MdiActiveDocument;

Editor ed = doc.Editor;

// Ask the user to select an entity

// for which to retrieve XData

PromptEntityOptions opt = new PromptEntityOptions("\nSelect entity: ");

PromptEntityResult res = ed.GetEntity(opt);



if (res.Status == PromptStatus.OK)
{

Transaction tr = doc.TransactionManager.StartTransaction();

using (tr)
{

DBObject obj = tr.GetObject(res.ObjectId, OpenMode.ForWrite);

obj.XData = new ResultBuffer();
tr.Commit();
tr.Dispose();
}

}

} Message was edited by: Niwrex
3 REPLIES 3
Message 2 of 4
NathTay
in reply to: S.Sameith

This sub removes the XDATA for a specified application from the specified object.


Public Sub RemoveXData(ByVal objEntId As ObjectId, ByVal strAppName As String)
Dim objDB As Database = objEntId.Database
Dim objTrans As Transaction = objDB.TransactionManager.StartTransaction
Dim objEnt As Entity = CType(objTrans.GetObject(objEntId, DatabaseServices.OpenMode.ForWrite, False), Entity)
If objEnt.GetXDataForApplication(strAppName) Nothing Then
Dim objResBuf As ResultBuffer = New ResultBuffer
objResBuf.Add(New TypedValue(1001, strAppName))
objEnt.XData = objResBuf
End If
objTrans.Commit()
objTrans.Dispose()
End Sub
Message 3 of 4
S.Sameith
in reply to: S.Sameith

Hi,

So now i do this and it works.

using (tr)
{

DBObject obj = tr.GetObject(res.ObjectId, OpenMode.ForWrite,false);
ResultBuffer resBuff = new ResultBuffer();
resBuff.Add(new TypedValue(1001,strAppName));
obj.XData = resBuff;
tr.Commit();
tr.Dispose();

}
But why i have to Add the Appname and the Type to the ResultBuffer if i want to delete it...
normaly i would say i have to create a new Resultbuffer which is empty and overwrite the XData, but this not work.
Message 4 of 4
Anonymous
in reply to: S.Sameith

Because XData attached to an DBObject could belong to many different
applications, some of which may not be written by you. So, in general, you
only want to "remove" XData that belongs to certain application. You surely
know that you can add/remove RegAppTableRecord to/from RegAppTable of
Database to register/unregister an XData application, don't you?

"Niwrex" wrote in message news:5961051@discussion.autodesk.com...
Hi,

So now i do this and it works.

using (tr)
{

DBObject obj = tr.GetObject(res.ObjectId,
OpenMode.ForWrite,false);
ResultBuffer resBuff = new ResultBuffer();
resBuff.Add(new TypedValue(1001,strAppName));
obj.XData = resBuff;
tr.Commit();
tr.Dispose();

}
But why i have to Add the Appname and the Type to the ResultBuffer if i want
to delete it...
normaly i would say i have to create a new Resultbuffer which is empty and
overwrite the XData, but this not work.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost