Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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. Some of them are a few years old. Is it currently possible to interact with Revit from Python executed outside 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.

like image 814
Marcus Jones Avatar asked Mar 11 '23 22:03

Marcus Jones


2 Answers

You cannot call the Revit API from another process. 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.

However, this DLL can talk with other processes via a mechanism like COM for example.

like image 83
Maxence Avatar answered Mar 14 '23 12:03

Maxence


As mentioned before, it is not possible to call Revit API from another process. In the aformentioned DLL you can implement IExternalEventHandler interface to be able to call API using event.

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();
like image 42
Marek Trawczynski Avatar answered Mar 14 '23 12:03

Marek Trawczynski