Start Revit API from external application

Start Revit API from external application

Anonymous
Not applicable
2,178 Views
8 Replies
Message 1 of 9

Start Revit API from external application

Anonymous
Not applicable

Sorry, I can't start Revit API. Variants I tried to create new object:

 

  1. Set RevtApp = CreateObject("Autodesk.Revit.Application")
  2. Set RevtApp = CreateObject(,"Autodesk.Revit.Application")
  3. Set RevtApp = CreateObject("Revit.Application")
  4. Set RevtApp = CreateObject(,"Revit.Application")
  5. Set RevtApp = CreateObject("Autodesk.Revit.Application.15")

But it doesn't work. All time I get error message - "You can't create object with ActiveX container".

Please help, I try to work with Revit API  from external application

0 Likes
2,179 Views
8 Replies
Replies (8)
Message 2 of 9

arnostlobel
Alumni
Alumni
Hello damirrevitapi:

I am sorry to let you know that what you want to do is not possible with the Revit API. Revit cannot get started from a standalone application. Revit must be always started as an independent application in its own process. Once Revit starts, it creates the API Application object. It is a singleton that nothing else but Revit can instantiate. An external application can get to this existing instance of Application via one of the available ways of API interactions, such as external commands and external applications. Those are the only ways of communicating with Revit via its API.
Arnošt Löbel
0 Likes
Message 3 of 9

Anonymous
Not applicable

Thank you!

 

"An external application can get to this existing instance of Application via one of the available ways of API interactions, such as external commands and external applications"

 

- what does it mean? How I can get to existing instance? 

I have external app. This app avaliable to make scripts on VBScript.

0 Likes
Message 4 of 9

arnostlobel
Alumni
Alumni

What do you mean by "What does it mean?"? 🙂

 

It means what it states: the instance (the only one in existence in each Revit session) is available to an external application during standard interactions between Revit and the external application. For example, in case of an external command, the command's Execute method has access to the application via the arguments of the Execute method. Similarly, an external application has access to the Application object via the argument of the OnStartup and OnShutdown method. It has the form of an instance of a ControlledUIApplication, which is the same thing like Application only with limited functionality, for the complete functionality of Revit is not available at the time of either OnStartup or OnShutdown. Also, external applications have access to the Application object during standard application events such as DocumentOpening, DocumentCreated, ApplicationInitialized, etc. In these cases and events alike the Application object (or UIApplication, depending on the event) is the "Sender" object a handler of the event receives as one of the arguments (typically the first one).

 

More on these issues is available in the SDK documentation, primarily in the help file RevitAPI.chm, but also im many of the samples provided with the SDK.

Arnošt Löbel
0 Likes
Message 5 of 9

Anonymous
Not applicable

command, the command's Execute method has access to the application via the arguments of the Execute method

 

So, how I can make external command to get access to Revit API?

 

 

an external application has access to the Application object via the argument of the OnStartup and OnShutdown method

How I can set external app to get access to the App object via the argument of the OnStartup and OnShutdown method?

 

The main problem is to set contact between my ExtApp and Revit

0 Likes
Message 6 of 9

arnostlobel
Alumni
Alumni

Hello damirrevitapi:

 

I am a bit confused by your questions. Before I'll go any further, let me ask: Have you already looked at the samples we provid in our SDK or have you tried to build some of the walk-throughs we document in our Revit API on-line Help? If not, I definitely recommend you start there. Here's a link to the help web site: Revit API On-Line Help. All the samples there and in the SDK make use of either an External Application or External Command. Your application must be one of those in order for that application be able to communicate with Revit (via the API). 

 

In a nutshell, though, and since you asked, here is the basic approach:

 

  • To make an External Command you create a class that implements IExternalCommand interface of which declaration you'll find in the RevitAPIUI assembly. The interface is very simple - it has only one menthod: Execute.
  • To make an External Application you create a class that implements IExternalApplication interface of which declaration you'll find in the RevitAPIUI assembly. The interface is very simple - it has only two menthods: OnStartup, and OnShutdown.
  • To be able to access the interfaces mentioned above and also all the classes in the Revit API, your assembly must reference both RevitAPI.DLL and RevitAPIUI.DLL where all the classes are defined.

 

 

Arnošt Löbel
0 Likes
Message 7 of 9

Anonymous
Not applicable

Sorry for delay!

Thank you for your answer. I observed you solution already. But now I have an idea.

Users export RVT files to DWF (Autodesk Design Review files). So I can count number of layouts inside the DWF files. Please tell me can I use ADR API like a common ActiveX control (set ADR = CreateObject(...))? 

On this webpage I found some infomation about it. Please confirm it

0 Likes
Message 8 of 9

arnostlobel
Alumni
Alumni

Maybe somebody else can step in to answer that, but I am not at all familiar with ADR API; I am sorry, I only do Revit.

Arnošt Löbel
0 Likes
Message 9 of 9

Anonymous
Not applicable

So anyway thank you for helping. This time I hope to use ADR API like a ActiveX control. Can I find some information about ADR API coding theme, if you know of course.

0 Likes