Revit二次开发——使用IExternalApplication定制UI

UIControlledApplication类是一种特殊的应用类,他不提供访问Revit文档的途径。因为UIControlledApplication只在OnStartup和OnShutdown函数范围内起作用,该类提供访问定制UI和注册事件的方法。
简单例子如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using System.Windows.Media.Imaging;

namespace CsAddpanel
{
    public class CsAddPanel : Autodesk.Revit.UI.IExternalApplication
    {
        public Autodesk.Revit.UI.Result OnStartup(UIControlledApplication application)
        {
            //add new ribbon panel
            RibbonPanel ribbonPanel = application.CreateRibbonPanel("NewRibbonPanel");

            //creat apush button in the ribbon panel  "NewRibbonPanel"
            //the add-in application "HelloWorld" willbe triggered when button is pusged
            PushButton pushButton = ribbonPanel.AddItem(new PushButtonData("HelloWorld", "HelloWorld", @"D:\VSProject\HelloWorld\HelloWorld\bin\Debug\HelloWorld.dll", "HelloWorld.Class1")) as PushButton;

            //Set yhe large image shown on button 
            Uri uriImage = new Uri(@"D:\VSProject\HelloWorld\HelloWorld\bin\Debug\1.png");
            BitmapImage largeImage = new BitmapImage(uriImage);
            pushButton.LargeImage = largeImage;

            return Result.Succeeded;
        }
        public Result OnShutdown(UIControlledApplication application)
        {
            return Result.Succeeded;
        }
    }
}

你可能感兴趣的:(revit,Revit二次开发)