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;
}
}
}