revit-apirevitrevitpythonshellpyrevit

Revit API - How to return to "normal code" after PostCommand is called


I've been looking around for an answer but I haven't found anything that addresses it.

I have a thread that calls a PostCommand and I've noticed a couple of things: No matter where I put the PostCommand, it occurs last in my thread even if it's inside a separate transaction.

Is there any way to call it in order and then return to my Revit API code to continue executing?

I've found this thread but I'm hoping their error is because they're running in dynamo instead of using c# in visual studio


Solution

  • Revit and the Revit API is single threaded.

    You can only call PostCommand in a valid Revit API context, and that context is within the single thread.

    Whatever command requests you post, they will not be executed until after your external command or other event handler has terminated and relinquished control, so Revit can resume doing whatever it wants to do next.

    You have no further control over that.

    As soon as your event handler terminates, Revit is back in normal mode.

    There is nothing you can do to change that in any way.