Handling Errors

Handling Errors

PaulCollins7972
Advocate Advocate
2,113 Views
2 Replies
Message 1 of 3

Handling Errors

PaulCollins7972
Advocate
Advocate

Hi

 

I am not quite sure how to solve and hide error messages genereated by copy/paste in API.

 

I have this which hides warning messages and deletes the elements causing an error,this works ok but still shows the error message to the user:

 

'suppress all warnings
For Each f As FailureMessageAccessor In failList

Dim fs As FailureSeverity = fa.GetSeverity
Select Case fs


Case FailureSeverity.Warning
'hide messages of severity "Warning"
fa.DeleteWarning(f)


Case FailureSeverity.Error
Dim elist As List(Of ElementId) = f.GetFailingElementIds
fa.DeleteElements(elist)
fa.ResolveFailure(f)

Return FailureProcessingResult.ProceedWithCommit


Case Else
Return FailureProcessingResult.ProceedWithRollBack
End Select
Next

 

This is called by the transaction options:

If t.Start() = TransactionStatus.Started Then
Dim FailOpt As FailureHandlingOptions = t.GetFailureHandlingOptions()
FailOpt.SetFailuresPreprocessor(New myFailurePreProcessor())
t.SetFailureHandlingOptions(FailOpt)

 

I have seen Jeremy's post  of May 7 2014 on handling warnings and failures and adapt the example c# code to vb as:

 

Private Sub DoFailureProcessing(sender As Object, args As Autodesk.Revit.DB.Events.FailuresProcessingEventArgs)
Dim failuresAccessor As FailuresAccessor = args.GetFailuresAccessor()
'failuresAccessor

Dim fmas As IList(Of FailureMessageAccessor) = failuresAccessor.GetFailureMessages()
If fmas.Count = 0 Then
args.SetProcessingResult(FailureProcessingResult.[Continue])
Return
End If


For Each fma As FailureMessageAccessor In fmas
Dim id As FailureDefinitionId = fma.GetFailureDefinitionId()
failuresAccessor.ResolveFailure(fma)
Next

 

args.SetProcessingResult(FailureProcessingResult.ProceedWithCommit)
Return

End Sub

 

What I am struggling with is how to get the DoFailureProcessing code to be triggered?

 

(I am using Revit 2016, VS2012 and VBdotNet)

 

Any help appreciated

Paul

0 Likes
Accepted solutions (1)
2,114 Views
2 Replies
Replies (2)
Message 2 of 3

arnostlobel
Alumni
Alumni
Accepted solution

What you need is to subscribe to FailuresProcessingEvent.

Keep in mind, though, that unlike the failure pre-processor, the event is raised for failures of all and every transaction no matter who made it. Thus it is probably a good idea to un-subscribe from the event when you applications stops being involved with mode changes.

 

By the way, you should only attempt resolving failures that are resolvable; Not every failure can be resolved.

Arnošt Löbel
0 Likes
Message 3 of 3

augusto.goncalves
Alumni
Alumni
And check the \Revit 2016 SDK\Samples\ErrorHandling sample for more details.
Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes