【问题标题】:Accessing Revit API from outside Revit从 Revit 外部访问 Revit API
【发布时间】:2016-10-24 04:24:58
【问题描述】:

我使用过 RevitPythonShell 和 Dynamo,但想使用我现有的 Python IDE (Eclipse),我在其中配置了日志记录、调试、GitHub 集成等。

我对事务和整体 API 感到满意,并且我花一些时间阅读有关 Revit API 和无模式连接以及其他人提出类似问题的信息。其中一些已经有几年的历史了。目前是否可以通过在 Revit 外部执行的 Python 与 Revit 进行交互?

例如,我试过了;

import clr
clr.AddReference(r'C:\Program Files\Autodesk\Revit 2016\RevitAPI')
import Autodesk.Revit.DB as rvt_db
print(dir(rvt_db))

但这似乎并没有暴露任何有用的东西。

【问题讨论】:

    标签: python revit-api revitpythonshell pyrevit


    【解决方案1】:

    您不能从其他进程调用 Revit API。该 API 设计为“进程内”使用,因此您必须创建一个 DLL,Revit 会将其加载到自己的进程中。

    【讨论】:

    • Marcus,看看 RevitPythonShell 源代码。 RPS 的创建者 Daren Thomas 添加了一个非模态模式,该模式使用预配置的处理程序调用以非模态形式运行输入的脚本。它仍在 revit 中,但 RPS 实际上要求 revit 运行它。也许这会帮助你想办法。
    【解决方案2】:

    如前所述,无法从其他进程调用 Revit API。在上述 DLL 中,您可以实现 IExternalEventHandler 接口,以便能够使用事件调用 API。

    class MyExecutionClass : IExternalEventHandler
    {
        public void Execute(UIApplication uiapp)
        {
            //your stuff
        }
        public string GetName()
        {
            return "My event executed class";
        }
    }
    
    //Create event on startup
    IExternalEventHandler myEventHandler = new MyExecutionClass();
    ExternalEvent myExEvent = ExternalEvent.Create(myEventHandler );
    
    //Pass event reference and raise it whenever yoo want
    myExEvent.Raise();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-15
      • 2020-04-20
      • 2020-09-15
      • 1970-01-01
      • 2020-02-17
      • 1970-01-01
      • 2019-03-29
      相关资源
      最近更新 更多