Arnaud
Arnaud

Reputation: 467

How to handle Failures within Revit API?

I'm trying to avoid getting warning messages when copying lots of walls with Revit 2018 API, for instance when some are overlapping. For that, I'm implementing the FailureHandler class as documented on the Building Coder, slightly adapted for Python, as also documented here.

Now, on a simple test case, copying a few walls that don't raise any warning/errors (I tried without taking care of failures, just copying walls, it works perfectly without any error), when I do implement and use the FailureHandler class, all my wall creation Transactions are RolledBack. They shouldn't, since there are no warnings! I reduced the FailureHandler implementation to its strict minimum to try to understand the behavior, but it keeps rolling back the transactions...

Here is my implementation for FailureHandler:

class FailureHandler(IFailuresPreprocessor):
  def __init__(self):
    self.ErrorMessage = ""
    self.ErrorSeverity = ""
  def PreprocessFailures(self, failuresAccessor):
    return FailureProcessingResult.ProceedWithCommit

As you can see, I'd expect it just to proceed with the Transaction. But it rolls back.

The main routine:

wallTransaction = Transaction(doc,"creating new walls")
wallTransaction.Start()

failureHandlingOptions = wallTransaction.GetFailureHandlingOptions()
failureHandler = FailureHandler()
failureHandlingOptions.SetFailuresPreprocessor(failureHandler)
failureHandlingOptions.SetClearAfterRollback(True)
wallTransaction.SetFailureHandlingOptions(failureHandlingOptions)

newWall = Wall.Create(doc, geoLine, wallTypeId, levId, wallHeight, 0, False, True)

wallTransaction.Commit()
print wallTransaction.GetStatus()

Again, without all these failureHandler considerations, this routine creates the walls without warning/errors.

can somebody explain me why it rolls back? Wouldn't FailureProcessingResult.ProceedWithCommit just imply that the transaction should commit?

Thanks a lot!

Upvotes: 0

Views: 1218

Answers (1)

Jeremy Tammik
Jeremy Tammik

Reputation: 8339

Please explore The Building Coder topic group on Detecting and Handling Dialogues and Failures, especially the last discussion on Gathering and Returning Failure Information.

Upvotes: 0

Related Questions