简体   繁体   English

从 Revit 外部访问 Revit API

[英]Accessing Revit API from outside Revit

I've used RevitPythonShell and Dynamo, but would like to use my existing Python IDE (Eclipse) where I have my configuration for logging, debugging, GitHub integration, etc.我使用过 RevitPythonShell 和 Dynamo,但想使用我现有的 Python IDE (Eclipse),在那里我有我的日志记录、调试、GitHub 集成等配置。

I'm comfortable with transactions and the overall API, and I've invested some time in reading about the Revit API and modeless connections, and others asking similar questions.我对事务和整个 API 很满意,并且我花了一些时间阅读有关 Revit API 和无模式连接的信息,以及其他提出类似问题的人。 Some of them are a few years old.其中一些已经有几年的历史了。 Is it currently possible to interact with Revit from Python executed outside Revit?目前是否可以通过在 Revit 之外执行的 Python 与 Revit 进行交互?

For example, I've tried;例如,我已经尝试过;

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

But this doesn't seem to expose anything useful.但这似乎没有暴露任何有用的东西。

You cannot call the Revit API from another process.不能从其他进程调用 Revit API。 The API is designed to be used "in-process", so you have to make a DLL which will be loaded by Revit into its own process. API 设计为在“进程内”使用,因此您必须制作一个 DLL,该 DLL 将由 Revit 加载到其自己的进程中。

As mentioned before, it is not possible to call Revit API from another process.如前所述,无法从其他进程调用 Revit API。 In the aformentioned DLL you can implement IExternalEventHandler interface to be able to call API using event.在上述 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM