Revit二次开发之入门

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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值