How to show Warning Errors when use doc.Delete

Anonymous

How to show Warning Errors when use doc.Delete

Anonymous
Not applicable

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:

warning.PNG

But when I use doc.Delete(id), Revit doesn't show any warning.

What I have to do? Please suggest.

Thank you!

0 Likes
Reply
418 Views
3 Replies
Replies (3)

Anonymous
Not applicable

still waiting for the solution...

0 Likes

adam.krug
Advocate
Advocate

I would skip the below part. Then warnings should be displayed for a user.

FailureHandlingOptions failOpt = trans.GetFailureHandlingOptions();
                    failOpt.SetFailuresPreprocessor(new WarningDiscard());
                    trans.SetFailureHandlingOptions(failOpt); 

 

0 Likes

Anonymous
Not applicable

Hi Adam,

I tried it but Revit still delete without any Warnings.

0 Likes