Message 1 of 4
How to show Warning Errors when use doc.Delete
Not applicable
10-28-2018
11:31 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
I'm a newbie in Revit API. My idea is to delete all selection element, if there is any warning -> rollback. Below is my code.
List<ElementId> idList = uidoc.Selection.GetElementIds().ToList();
foreach (ElementId id in idList)
{
using (Transaction trans = new Transaction(doc, "Delete"))
{
trans.Start();
FailureHandlingOptions failOpt = trans.GetFailureHandlingOptions();
failOpt.SetFailuresPreprocessor(new WarningDiscard());
trans.SetFailureHandlingOptions(failOpt);
try
{
doc.Delete(id);
}
catch
{
continue;
}
trans.Commit();
}
}public class WarningDiscard : IFailuresPreprocessor
{
FailureProcessingResult
IFailuresPreprocessor.PreprocessFailures(FailuresAccessor failuresAccessor)
{
IList<FailureMessageAccessor> fmas = failuresAccessor.GetFailureMessages();
if (fmas.Count > 0)
{
return FailureProcessingResult.ProceedWithRollBack;
}
return FailureProcessingResult.Continue;
}
}My problem is: when I delete manually (by using Delete keyboard), Revit showed:
But when I use doc.Delete(id), Revit doesn't show any warning.
What I have to do? Please suggest.
Thank you!