简体   繁体   English

如何使用C#在API中加载Revit文件?

[英]How to load Revit file in API using C#?

I want to load the *.api file in C# code. 我想以C#代码加载*.api文件。 I am trying to export the images from Revit file for specific views in c# application. 我正在尝试从Revit文件中导出图像以在c#应用程序中使用特定视图。 The issue is to get the ExternalCommandData from revit ( *.rvt ) file. 问题是从revit( *.rvt )文件中获取ExternalCommandData。

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. 我想浏览所有*.rvt文件并从Windows窗体调用上述方法。

I just answered your corresponding thread in the Revit API discussion forum: 我刚刚在Revit API论坛中回答了您的相应主题:

https://forums.autodesk.com/t5/revit-api-forum/how-to-load-revit-file-in-api-using-c/mp/7071015 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. 从外部上下文直接调用Revit API曾经是,过去一直都是非法的。

The Revit API cannot ever be used except within a valid Revit API context. 只有在有效的Revit API上下文中,才能使用Revit API。

Such a context is provided exclusively by Revit call-back methods. 这样的上下文由Revit回调方法专门提供。

You need to subscribe to a Revit event, such as an external command Execute method. 您需要预订Revit事件,例如外部命令Execute方法。

Within the event handler, the Revit API can be used. 在事件处理程序中,可以使用Revit API。

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. 您还可以使用Revit API设置可以从非Revit-API上下文引发的外部事件,例如独立的外部应用程序。

This is demonstrated by the ModelessDialog/ModelessForm_ExternalEvent Revit SDK sample. 这可以通过ModelessDialog / ModelessForm_ExternalEvent Revit SDK示例进行演示。 Here is all you need to know about the Revit SDK and getting started with the Revit API . 这是您需要了解的有关Revit SDK和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. 过去,在Revit API讨论论坛和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 . 《建筑规范》主题组中的许多示例和进一步说明提供了有关从外部进行无模式访问和驱动Revit的空闲和外部事件的信息

Here are some of the Revit API forum discussion threads addressing similar issues: 以下是解决类似问题的一些Revit API论坛讨论线程:

Revit can only run plugins in-process, therefore you cannot use its API from a WinForm app. Revit只能在进程内运行插件,因此无法从WinForm应用程序使用其API。 The Execute method you mentioned is, in fact, called by Revit on the DLL code. 您提到的Execute方法实际上是由Revit在DLL代码上调用的。

If all you want to do is export images from the RVT or RFA file, your needs may already be completely covered by Forge . 如果您要做的只是从RVT或RFA文件中导出图像,那么Forge可能已经完全满足了您的需求。 For full details on how and why, please refer to my blog post on External Access to the Revit API . 有关如何以及为什么的完整详细信息,请参阅我关于Revit API的外部访问的博客文章。

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

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