简体   繁体   中英

How to load Revit file in API using C#?

I want to load the *.api file in C# code. I am trying to export the images from Revit file for specific views in c# application. The issue is to get the ExternalCommandData from revit ( *.rvt ) file.

public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit, 
                                        ref string message, ElementSet elements)
{
    UIApplication uiapp = revit.Application;
}

I want to browse all *.rvt file and call above method from the Windows form.

I just answered your corresponding thread in the Revit API discussion forum:

https://forums.autodesk.com/t5/revit-api-forum/how-to-load-revit-file-in-api-using-c/mp/7071015

Calling directly into the Revit API from an external context is, was and always has been illegal.

The Revit API cannot ever be used except within a valid Revit API context.

Such a context is provided exclusively by Revit call-back methods.

You need to subscribe to a Revit event, such as an external command Execute method.

Within the event handler, the Revit API can be used.

You can also use the Revit API to set up an external event that can be raised from a non-Revit-API context, such as your standalone external application.

This is demonstrated by the ModelessDialog/ModelessForm_ExternalEvent Revit SDK sample. Here is all you need to know about the Revit SDK and getting started with the Revit API .

This question has been answered and discussed in depth numerous times in the past, both in the Revit API discussion forum and by The Building Coder.

Many examples and further explanations are provided in The Building Code topic group on Idling and External Events for Modeless Access and Driving Revit from Outside .

Here are some of the Revit API forum discussion threads addressing similar issues:

Revit can only run plugins in-process, therefore you cannot use its API from a WinForm app. The Execute method you mentioned is, in fact, called by Revit on the DLL code.

If all you want to do is export images from the RVT or RFA file, your needs may already be completely covered by Forge . For full details on how and why, please refer to my blog post on External Access to the Revit API .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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