/// <summary>
/// Deletes xdata under the regsitered app specified.
/// </summary>
/// <param name="objID">The object identifier.</param>
/// <param name="appName">name of the registered app to delete</param>
public static void DeleteXData(ObjectId objID, string appName)
{
if (appName.Length<1) return;
ResultBuffer updatedXdata
= new ResultBuffer
(); using (LockedTransaction tr = Active.Document.TransactionManager.StartLockedTransaction())
{
// remove any xdata for the given appname
DBObject obj = tr.GetObject(objID, OpenMode.ForWrite);
ResultBuffer existingData = obj.XData;
if (existingData!=null)
{
bool included = true;
// Get all values NOT with our Registered App
foreach (TypedValue tv in existingData)
{
// check whether to keep it
if (tv.TypeCode == CODE_APPNAME)
{
if (appName.Equals(tv.Value.ToString()))
{
// add the appname TV or the xData doesn't get set correctly and reverts back to the old xData
updatedXdata.Add(tv);
included = false;
}
else
{
included = true;
}
}
if (included)
{
updatedXdata.Add(tv);
}
}
RegisterApps(updatedXdata);
obj.XData = updatedXdata;
}
tr.Commit();
}
}