- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Everyone:
I am a newcomer to develop RevitAPI,now I have a question about suppressing warning messages.
when we use "Paste/ AlignedToSelectedLevels"command to paste elements, if some of these are overlap, Revit displays the following warning message:
Now I creat a addin, in which I use “uiapp.PostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.AlignedToSelectedLevels));” to paste some elements ,meanwhile I want to suppressing this warning messages and get these messages .
This is my code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.Events;
using System.Threading;
namespace DeleteWarningElement
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
[Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;
uiapp.PostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.AlignedToSelectedLevels));
Transaction transaction = new Transaction(doc, "BIM");
FailureHandlingOptions options = transaction.GetFailureHandlingOptions();
options.SetFailuresPreprocessor(new FailurePreproccessor());
transaction.SetFailureHandlingOptions(options);
transaction.Start();
TaskDialog.Show("1", "12");
Thread.Sleep(5000);
transaction.Commit();
return Result.Succeeded;
}
}
public class FailurePreproccessor : IFailuresPreprocessor
{
public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor)
{
IList<FailureMessageAccessor> failList = failuresAccessor.GetFailureMessages();
if (failList.Count == 0)
{
TaskDialog.Show("1", failList.Count().ToString());
return FailureProcessingResult.Continue;
}
foreach (FailureMessageAccessor failure in failList)
{
TaskDialog.Show("1", "123");
FailureDefinitionId failID = failure.GetFailureDefinitionId();
if (BuiltInFailures.CopyPasteFailures.CannotDuplicateWarn==failID)
{
failuresAccessor.DeleteWarning(failure);
}
}
return FailureProcessingResult.ProceedWithCommit;
}
}
}When I executed the code, I found this warning was not suppressed. I also found that“ Transaction transaction = new Transaction(doc, "BIM"); ” is a null operation, so what is Transaction of PostCommand in Revit .
how to solve this problem?
Looking forward to your reply!
GoodLuck!
Solved! Go to Solution.
