Errorhandler cpython

Errorhandler cpython

sander_de_weert
Community Visitor Community Visitor
159 Views
0 Replies
Message 1 of 1

Errorhandler cpython

sander_de_weert
Community Visitor
Community Visitor

For multiple reasons, I use Cpython with pyrevit, by starting the script.py file with #!python3. 

 

When executing the script, I run into multiple warning. I'd like to skip these warning, by editing the PreprocessFailures method (like below). I got it working for Cpython (.NET) by adding the __namespace__ = EXEC_PARAMS.exec_id parameter to the definition of the class.

 

Somehow, when I run the script, when warning occure, everything is executed, but it is not possible to use Revit. The last line of the full script is printed. It only happens when I add the custom Error handler into one of the transaction. All together there are about 20 transactions/commits in the processes.

 

What can be the problem?

 

from Autodesk.Revit.DB import IFailuresPreprocessor, FailureProcessingResult, FailureSeverity
from pyrevit import EXEC_PARAMS


class SupressWarnings(IFailuresPreprocessor):
__namespace__ = EXEC_PARAMS.exec_id

def PreprocessFailures(self, failuresAccessor):
failures = failuresAccessor.GetFailureMessages()
for fail in failures: # type: FailureMessageAccessor
fail_ids = fail.GetFailingElementIds()
severity = fail.GetSeverity()
description = fail.GetDescriptionText()

if severity == FailureSeverity.Warning:
print(f'Warning: {description}')
failuresAccessor.DeleteWarning(fail)
for fail_id in fail_ids:
print(fail_id)
elif severity == FailureSeverity.Error:
print(f'Error: {description}')
failuresAccessor.ResolveFailure(fail)
return FailureProcessingResult.ProceedWithCommit
else:
print(f'geen warning en geen error: {fail}')
return FailureProcessingResult.Continue
0 Likes
160 Views
0 Replies
Replies (0)