如何配置Revit二次开发的环境,创建Hello World应用程序
https://visualstudio.microsoft.com/zh-hans/vs/older-downloads/
VS的更新 http://download.microsoft.com/download/9/4/f/94f9f500-fe47-4a4e-be00-85350e2cf87a/vs2015.3%20rc.exe
https://www.autodesk.com/developer-network/platform-technologies/revit
2018版本的更新一点SDK:
http://download.autodesk.com/us/revit-sdk/REVIT_2018_2_SDK.msi
Documentation:Learn more about Revit's .NET API through Revit's API
The SDK is included in every Revit product. There are two ways to install the Revit SDK:
You can also download the updated Revit SDK here:
The Revit LookUp Tool can help debug the Revit Database and understand the elements and its parameters. The source code can be found at our GitHub repository.
https://github.com/jeremytammik/RevitLookup
4、revit2018的addinmanager安装
Revit二次开发 _AddInManager 安装步骤:
(1)已装Revit2018
(2)安装Revit SDK2018
(3)打开SDK2018 文件夹中的 Add-In Manager,找到 Autodesk.AddInManager.addin 文件,然后复制该文件到Revit 2018安装文件Addins中。
需要将.addin文件放置到C:\ProgramData\Autodesk\Revit\Addins\2018,这是一个隐藏文件夹,如果没有显示的话可以使用文件夹选项的“设置”将隐藏文件夹显示。
(4)用记事本(或用编程软件)打开复制过的 Autodesk.AddInManager.addin 文件。
然后修改下图红色框内的内容,修改为:自己SDK2018中Add-In Manager文件安装位置(下图已修改好)。
(5)打开Revit2018 ,查看
5、revit2018的revitlookup安装
(1)参照“3”下载revitlookup的源代码文件,并解压。
(2)编译生成revitlookup.dll文件:用VS2015打开源代码后,首先需要重新连接引用的Revit的DLL,如下图,配置一下属性,生成DLL。
(3)revitlookup.dll放到revit的安装路径;
(4)再将revitlookup.addin放到C:\ProgramData\Autodesk\Revit\Addins\2018下;
(5)最后将addin文件的
运行Revit软件后,Revit会自动添加插件。可能有安全性提示,点击总是载入即可。
加载后的界面如图所示:
(3)Add Code
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Autodesk.Revit.UI; using Autodesk.Revit.DB;
namespace HelloWorld { [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] public class Class1 : IExternalCommand { public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit, ref string message, ElementSet elements) { TaskDialog.Show("Revit", "Hello World"); return Autodesk.Revit.UI.Result.Succeeded; } } } |
<RevitAddIns> <Assembly>E:\C#\sample\HelloWorld\HelloWorld\bin\Debug\HelloWorld.dllAssembly> //此处的HelloWorld.dll在项目生成后才会有,开始看不到 <AddInId>239BD853-36E4-461f-9171-C5ACEDA4E721AddInId> //此处的ID在解决方案管理器项目中Properties的AssemblyInfo.cs中可以查看 <FullClassName>HelloWorld.Class1FullClassName> //此处的HelloWorld为项目名,Class1为类名 <Text>HelloWorldText> <VendorId>ADSKVendorId> <VendorDescription>Autodesk, www.autodesk.comVendorDescription> AddIn> RevitAddIns> |
击其中的调试(Debug),选择启动外部程序,将revit.exe的路径写出来即可。
最后进行调试,调试时会自动开启revit软件,在添加外部工具中可找到helloworld。
(一) public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
{
TaskDialog.Show("Revit", "Hello World");
return Autodesk.Revit.UI.Result.Succeeded;
}
UIApplication uiApplication =revit.Application;
Application application=uiApplication.Application;
UIDcument uiDocument=uiApplication.ActiveUIDocument;
Document document=uiDocument.Document;
外部命令可以通过这个参数返回执行过程中的错误信息。这个参数作用于整个外部命令的执行过程,用户可以在外部命令执行过程中的任何时候给这个信息设值或者追加信息。当外部命令的Execute函数返回Autodesk.Revit.UI.Result.Failed或者Autodesk.Revit.UI.Result.Canceled,这个错误信息将被显示在UI上。
当外部命令返回Autodesk.Revit.UI.Result.Failed或者Autodesk.Revit.UI.Result.Canceled并且message参数不为空的时候,错误或者警告对话框会弹出来,点击上面的显示按钮,elements参数中的元素将被高亮显示。
4、返回值 Execute函数的返回值表示外部命令的执行状态,有三种情况:Autodesk.Revit.UI.Result.Succeeded,Autodesk.Revit.UI.Result.Failed或者Autodesk.Revit.UI.Result.Canceled
如果返回不是Succeeded ,那么Revit会把外部命令所做的所有操作和修改都撤销。
(二)插件开发者同样可以通过IExternalApplication来添加自己的应用,Revit同样通过.addin文件来识别和加载IExternalApplication的外部插件。
IExternalApplication接口有两个抽象函数OnStartup和OnShutdown。用户可以通过在实现了IEcternalApplication的外部应用中重载OnStartup和OnShutdown函数,在Revit启动和关闭的时候定制所需要的功能。
// // 摘要: // An interface that supports addition of external applications to Revit. // // 备注: // External applications are permitted to customize the Revit UI, and to add events // and updaters to the session. public interface IExternalApplication { // // 摘要: // Implement this method to execute some tasks when Autodesk Revit shuts down. // // 参数: // application: // A handle to the application being shut down. // // 返回结果: // Indicates if the external application completes its work successfully. Result OnShutdown(UIControlledApplication application); // // 摘要: // Implement this method to execute some tasks when Autodesk Revit starts. // // 参数: // application: // A handle to the application being started. // // 返回结果: // Indicates if the external application completes its work successfully. Result OnStartup(UIControlledApplication application); } |
// // 摘要: // An interface that supports addition of DB-level external applications to Revit, // to subscribe to DB-level events and updaters. // // 备注: // DB-level applications are permitted to add DB-level events and updaters to the // session. They cannot create or modify UI. public interface IExternalDBApplication { // // 摘要: // Implement this method to execute some tasks when Autodesk Revit shuts down. // // 参数: // application: // Handle to the Revit Application object. // // 返回结果: // Indicates if the external db application completes its work successfully. ExternalDBApplicationResult OnShutdown(ControlledApplication application); // // 摘要: // Implement this method to execute some tasks when Autodesk Revit starts. // // 参数: // application: // Handle to the Revit Application object. // // 返回结果: // Indicates if the external db application completes its work successfully. // // 备注: // Typically, event handlers and updaters are registered in this method. ExternalDBApplicationResult OnStartup(ControlledApplication application); } |