1.接口
Revit二次开发主要因接口不同主要有作为外部工具的插件和作为附加模块插件两种形式;
1)IExternalCommand
用这个接口开发的插件,主要显示在附加模块→外部工具下;继承该接口的类需实现
Result Excute(ExternalCommandData commandData, out string message, ElementSet elements);
using Autodesk.Revit.Attributes;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace HelloWorld
{
[Transaction(TransactionMode.Automatic)]
[Regeneration(RegenerationOption.Manual)]
public class HelloWorldDialog : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,ref string message,ElementSet elements)
{
TaskDialog.Show("Revit", "Hello World");
return Result.Succeeded;
}
}
}
2)IExternalApplication
用这个接口开发的插件作为附加模块显示,主要显示在附加模块面板上;继承该接口的类需实现
Result OnShutdown(UIControlledApplication application)
该函数主要用来执行当Autodesk Revit关闭后的任务;
Resutl OnStartup(UIControlledApplication application)
该函数用来执行当Autodesk Revit开启时可执行的任务;
using Autodesk.Revit;
using Autodesk.Revit.UI;
//using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
namespace AddPanel
{
[Transaction(TransactionMode.Automatic)]
public class CsAddpanel :IExternalApplication
{
public Result OnStartup(UIControlledApplication application)
{
//add new ribbon panel
RibbonPanel ribbonPanel = application.CreateRibbonPanel("NewRibbonPanel");
PushButton pushButton = ribbonPanel.AddItem(new PushButtonData("HelloWorld",
"HelloWorld", @"F:\test\Revit\HelloWorld\HelloWorld\bin\Debug\HelloWorld.dll", "HelloWorld.HelloWorldDialog")) as PushButton;
Uri uriImage = new Uri(@"F:\test\Revit\AddPanel\AddPanel\bin\Debug\browser.png");
BitmapImage largeImage = new BitmapImage(uriImage);
pushButton.LargeImage = largeImage;
return Result.Succeeded;
}
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
}
}