Hello,
I have a specific failure that I want to disable.
I'm able to 'catch' the error (With FailuresProcessing event).
The problem is that I can't find a way to disable / delete the error.
DeleteWarning only works for 'Warning' severity, and my failure is 'Error' severity.
Thanks in advance!
Solved! Go to Solution.
Solved by aignatovich. Go to Solution.
How do you handle the situation manually in the end user interface? Please note that the Revit API almost always just duplicates or provides access to the standard UI functionality.
I'd click 'Cancel' on the popup message (It's the message that warns that deleting a part will cause other parts to be deleted).
My goal is to not show this error.. I'm cancelling the operation itself by posting another failure message saying "operation was cancelled" but the warning of 'deleting part will cause other part to be deleted' is still shown
Yes, well if you click cancel, then the operation is aborted, isn't it?
I would assume that Revit absolutely refuses to perform this operation, because it would corrupt the entire BIM.
In the UI you have to cancel it, and in the API the same.
A warning is a warning and is permissible. An error is an error and is forbidden.
Or am I misunderstanding?
Sorry, I do not understand. If you want to delete the element causing the error, why don't you just delete it? Then, no error will be caused. You can see how lost I am here...
However, regardless of whether I understand or not, maybe the previous discussions of the Failure API functionality and usage will help solve the issue?
https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.32
Or previous discussions here in the forum?
Or maybe even the warning swallower?
Hi guys,
@tomerFUNPJ , I think, you could try to either resolve the failure or rollback transaction?
If so you could try to delete elements automatically in your failure preprocessor:
if (failureAccessor.HasResolutionOfType(FailureResolutionType.DeleteElements))
{
failureAccessor.SetCurrentResolutionType(FailureResolutionType.DeleteElements);
failuresAccessor.ResolveFailure(failureAccessor);
}
You should return FailureProcessingResult.ProceedWithCommit if you set resolution type.
This failure preprocessor solves a bit different task, but I think it could help you:
public class AutoDetachOrDeleteFailurePreprocessor : IFailuresPreprocessor
{
public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor)
{
var preprocessorMessages = failuresAccessor.GetFailureMessages(FailureSeverity.Error)
.Union(failuresAccessor.GetFailureMessages(FailureSeverity.Warning))
.Where(x => x.HasResolutionOfType(FailureResolutionType.DeleteElements) || x.HasResolutionOfType(FailureResolutionType.DetachElements))
.ToList();
if (preprocessorMessages.Count == 0)
return FailureProcessingResult.Continue;
foreach (var failureAccessor in preprocessorMessages)
{
failureAccessor.SetCurrentResolutionType(failureAccessor.HasResolutionOfType(FailureResolutionType.DetachElements) ? FailureResolutionType.DetachElements : FailureResolutionType.DeleteElements);
failuresAccessor.ResolveFailure(failureAccessor);
}
return FailureProcessingResult.ProceedWithCommit;
}
}
If you can't resolve the error with FailureResolutionType.DeleteElements, then you can return FailureProcessingResult.ProceedWithRollBack
In such case you have to set:
failureOptions.SetClearAfterRollback(true);
for your transaction.
Hope this helps
I'll explain my flow with more details:
- I'm successfully preventing the users from deleting parts that have a specific scheme I made
- No deletion is done whatsoever. Which is good - that was my goal
- Although no deletion is done, the user still get this warning:
I want to hide it because it can be confusing to my user. The problem is that - The severity of this message is 'Error' and not warning and therefore I can't use Failure Accessor 'DeleteWarning' method.
So my question is - Is is possible to prevent showing failures of 'Error' severity?
Thanks
Failures with "Error" severity could not be "swallowed". They should be resolved using some resolution type (if supported) or by transition rollback. If the transition is rolled back and you don't want to see messages in the UI, you should set clear after rollback transition option
This is my PreprocessFailures
I'm getting in the for loop, and inside my if statement. And of course - returning ProceedWithRollback. The error still appears..
public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor)
{
IList<FailureMessageAccessor> failList = new List<FailureMessageAccessor>();
failList = failuresAccessor.GetFailureMessages(); // Inside event handler, get all warnings
foreach (FailureMessageAccessor failure in failList)
{
FailureDefinitionId failID = failure.GetFailureDefinitionId();
if (failID == BuiltInFailures.DPartFailures.DeletingDPartWillDeleteMorePartsError)
{
failure.SetCurrentResolutionType(FailureResolutionType.Default);
failuresAccessor.ResolveFailure(failure);
failuresAccessor.GetFailureHandlingOptions().SetClearAfterRollback(true);
return FailureProcessingResult.ProceedWithRollBack;
}
}
return FailureProcessingResult.Continue;
}
From SDK (FailureResolutionType):
Default - Special (reserved) type. It cannot be used as a type when defining a resolution, but can be used as a key to query default resolution from FailureMessage or FailureDefinition.
I don't think you have to call "ResolveFailure" if you want to rollback the transaction
I would try to set "clear after rollback" through transaction options before starting the transaction, e.g.:
var failureOptions = transaction.GetFailureHandlingOptions();
failureOptions.SetClearAfterRollback(true);
...
transaction.SetFailureHandlingOptions(failureOptions);
transaction.Start();
But I'm not starting any transaction.. 🙂 At any point
This method is triggered by the user - When he tries to delete an element (that's what I want). I'm preventing the user from deleting the element (Raising a different error saying "Operation is cancelled".)
I just don't want to get the error I attached in the picture a few comments above..
Do you use
Application.RegisterFailuresProcessor
method?
I personally would suggest to avoid this...
From SDK:
I am registered to FailuresProcessing 🙂
uiControlledApplication.ControlledApplication.FailuresProcessing += ControlledApplication_FailuresProcessing;
And it still shows the error..
I am also using IFailuresPreprocessor:
public class FailuresPreProcessor : IFailuresPreprocessor
{
public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor)
{
IList<FailureMessageAccessor> failList = new List<FailureMessageAccessor>();
failList = failuresAccessor.GetFailureMessages(); // Inside event handler, get all warnings
foreach (FailureMessageAccessor failure in failList)
{
FailureDefinitionId failID = failure.GetFailureDefinitionId();
if (failID == BuiltInFailures.DPartFailures.DeletingDPartWillDeleteMorePartsError)
{
failure.SetCurrentResolutionType(FailureResolutionType.Others);
failuresAccessor.GetFailureHandlingOptions().SetClearAfterRollback(true);
failuresAccessor.ResolveFailure(failure);
return FailureProcessingResult.ProceedWithRollBack;
}
}
return FailureProcessingResult.Continue;
}
}
Thanks so much for trying to help. I appreciate it!
I guess you should pick one. Have you tried to remove ResolveFailure and left only
return FailureProcessingResult.ProceedWithRollBack;
?
Can't find what you're looking for? Ask the community or share your knowledge.