.NET

Reply
Active Member
S.Sameith
Posts: 9
Registered: ‎11-28-2007
Message 1 of 4 (639 Views)

Delete XData

639 Views, 3 Replies
06-18-2008 03:48 AM
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
Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 2 of 4 (639 Views)

Re: Delete XData

06-18-2008 04:22 PM 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
Active Member
S.Sameith
Posts: 9
Registered: ‎11-28-2007
Message 3 of 4 (639 Views)

Re: Delete XData

06-18-2008 11:26 PM 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.
*Norman Yuan
Message 4 of 4 (639 Views)

Re: Delete XData

06-19-2008 01:10 PM 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.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!