revit二次开发——HelloRevit入门案例
-
打开vs,新建一个类库项目
-
将RevitAPI、RevitAPIUI添加到引用,将其属性【复制到本地改为False】
-
编写代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
namespace HelloWord
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
TaskDialog.Show("Demo", "hello first revit program");
return Result.Succeeded;
}
}
}
- 右击项目,查看属性,将启动设置为启动外部程序,选择Revit.exe,启动生成HelloWord.dll文件
- 在“C:\Users\你的用户名\AppData\Roaming\Autodesk\Revit\Addins\2014”,创建一个addin文件,如HelloWorld.addin,用记事本打开编辑,添加如下内容:
<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
<AddIn Type="Command">
<VendorId>miror</VendorId>
<Text>Hello Revit</Text>
<Description>Hello World to Revit.</Description>
<FullClassName>helloworld.Command</FullClassName>
<Assembly>E:\1hololens\projects\revit\helloworld\helloworld\bin\Debug\helloworld.dll</Assembly>
<AddInId>2A7F31C5-8FDE-417F-8FE7-CF38768A5D69</AddInId>
</AddIn>
</RevitAddIns>
- 其中,各个字段的意义如下:
【VendorId】,开发商Id,可以自己随意取名。
【Text】,Revit中插件的名称。
【Description】,插件的描述信息。(可不写这项)
【FullClassName】,类名。注意:得填写完整的【命名空间.类名】,如本例的命名空间为helloworld,类名为command。
【Assembly】,需要加载的程序集的完整路径,调试的时候,可以填写debug目录下的dll路径。
【AddIn】,在VS的【工具】→【创建GUID】,选择注册表格式,可以取得,点击复制,粘贴到字段为“{2A7F31C5-8FDE-417F-8FE7-CF38768A5D69}”,删除前后括弧即可。