Starting a transaction from an external application running outside of API context is not allowed

江枫思渺然 提交于 2020-01-25 12:35:20

问题


Starting a transaction from an external application running outside of API context is not allowed. cannot start transaction.


回答1:


Using my magic psychic crystal ball to guess you are asking how to avoid getting this error message in your Revit / RPS plugins, here is a short bit of extra information:

  • all Revit API calls should happen inside the "API context"
  • this "API context" lives in a special thread
  • you are probably accessing the API from another thread
  • this often happens when you make a Formand call into the API from one of the events (Button.OnClick)

What you want to do is figure out how to get back into the API context to execute your code. There are two main methods for doing this (assuming you have already left the IExternalCommand.Execute context):

  • polling for jobs inside the Idling event
  • using an ExternalEvent

Since you mentioned RevitPythonShell in the tags, why don't you check out how I used external events in my web server example.

  • create an IExternalEventHandler
  • implement its Execute method
  • (the Execute method runs in the Revit API context)
  • create an ExternalEvent (using the event handler just created)
  • when you need to do something in the Revit API context, notify the external event (my_external_event.Raise())


来源:https://stackoverflow.com/questions/31490990/starting-a-transaction-from-an-external-application-running-outside-of-api-conte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!