Revit二次开发--"Add Hello World Ribbon Panel"

1.Create a New Project
1)创建C#中的类库项目。
2)将项目名称写为“Ribbon”。
3)添加RevitAPI.dll和RevitAPIUI.dll,并修改属性。
4)在解决方案资源管理器中,选择项目名称右键选择 “添加引用”。在对画框中选择 “程序集–框架”中的PresentationCore和WindowBase和System.Xaml,将其三个添加。

2.Change the Class Name
修改类名为”CsAddPanel”。
3.Add Code

using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using System.Windows.Media.Imaging;

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

//Create a push button in the ribbon panel"NewRibbonPanel"
//the add-in application "HelloWorld" will be triggered when button is pushed

PushButton pushButton = ribbonPanel.AddItem(new PushButtonData("HelloWorld","HelloWorld",@"E:\C#\sample\ HelloWorld\HelloWorld\bin\Debug\HelloWorld.dll", "HelloWorld.Class1")) as PushButton;
//此处的路径为helloworld的路径,及其项目名与类名。

//Set the large iamge Shown on button
            Uri uriImage = new Uri(@"E:\C#\sample\HelloWorld\HelloWorld\bin\Debug\39-Globe_32×32.png");
//此处的图片是自己下载的图标,将其放在helloworld的路径中
BitmapImage largeImage = new BitmapImage(uriImage);
pushButton.LargeImage = largeImage;

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

4.Build the Application
生成后得到 Ribbon.dll
5.Create the .addin manifest file

<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
  <AddIn Type="Application">
    <Name>SampleApplication</Name>
    <Assembly>E:\C#\sample\Ribbon\Ribbon\bin\Debug\Ribbon.dll</Assembly>
    <AddInId>e4db245e-0086-45e0-b671-2a49fb51d608</AddInId>
    <FullClassName>Ribbon.CsAddPanel</FullClassName>
    <VendorId>ADSK</VendorId>
    <VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
  </AddIn>
</RevitAddIns>

将其存入C:\ProgramData\Autodesk\Revit\Addins\2014中。

最后生成(F6)
将revit软件打开,在附加模块中就可以看到。

Revit二次开发--"Add Hello World Ribbon Panel"_第1张图片

你可能感兴趣的:(BIM,Panel,ribbon)