EaBIM

标题: Revit Ribbon 制作 [打印本页]

作者: 萧闫子    时间: 2014-1-9 13:21
标题: Revit Ribbon 制作
Revit 2011之后取消了菜单和工具条,全部使用Ribbon即按钮组,如图

                               
登录/注册后可看大图



步骤一:
新建类库项目Ribbon
修改命名空间为HY
修改Class1.cs为Ribbon.cs用来控制按钮显示
添加一个类AddInCommand.cs用来响应命令

步骤二:
引入类库
RevitAPI.dll
RevitAPIUI.dll
System.Windows.Forms;
PresentationCore
WindowBase

Ribbon.cs using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;
using System.Windows.Forms;
using System.Windows.Media.Imaging;

using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;

namespace HY
{
    [Transaction(TransactionMode.Automatic)]
    [Regeneration(RegenerationOption.Manual)]
    [Journaling(JournalingMode.NoCommandData)]
   
public
class Ribbon : IExternalApplication
    {
        
// 程序集路径

static
string AddInPath =
typeof(Ribbon).Assembly.Location;
        
// 按钮图标目录

static
string ButtonIconsFolder = undefinedath.GetDirectoryName(AddInPath);
        
// uiApplication
        
//static UIApplication uiApplication = null;

#region IExternalApplication Members
public Autodesk.Revit.UI.Result OnStartup(UIControlledApplication application)
        {
            
try
            {
                CreateRibbonSamplePanel(application);

               
return Autodesk.Revit.UI.Result.Succeeded;
            }
            
catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(),
"Ribbon Sample");

               
return Autodesk.Revit.UI.Result.Failed;
            }
        }

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

        
#endregion
private
void CreateRibbonSamplePanel(UIControlledApplication application)
        {
            
//RibbonPanel显示一个大按钮,图标为第一个按钮的图标

string firstPanelName =
"Ribbon 实例";//面板底部文字提示
            RibbonPanel ribbonSamplePanel = application.CreateRibbonPanel(firstPanelName);

            
#region 创建墙和结构墙
//RibbonPanel(面板)->SplitButton(按钮组)->undefinedushButton(按钮)
            SplitButtonData splitButtonData =
new SplitButtonData("NewWallSplit", "创建墙");//按钮数据,按钮组显示的文字为第一个按钮的文字
            SplitButton splitButton = ribbonSamplePanel.AddItem(splitButtonData) as SplitButton;//添加到面板

            
//PushButton pushButton = splitButton.AddPushButton(new undefinedushButtonData("WallPush", "普通墙", AddInPath, "Revit.SDK.Samples.Ribbon.CS.CreateWall"));
            
//最后一个参数是执行按钮事件的响应类名
            undefinedushButtonData pushButtonDataWall =
new undefinedushButtonData("WallPush", "普通墙", AddInPath, "HY.CreateWall");
            PushButton pushButton
= splitButton.AddPushButton(pushButtonDataWall);
            
//大图标,小图标
            pushButton.LargeImage =
new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "CreateWall.png"), UriKind.Absolute));
            pushButton.Image
=
new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "CreateWall-S.png"), UriKind.Absolute));
            
//提示文字,提示图片
            pushButton.ToolTip =
"Creates a partition wall in the building model.";
            pushButton.ToolTipImage
=
new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "CreateWallTooltip.bmp"), UriKind.Absolute));

            
//按钮组里第二个按钮
            pushButton = splitButton.AddPushButton(new PushButtonData("StrWallPush", "结构墙", AddInPath,"HY.CreateStructureWall"));
            pushButton.LargeImage
=
new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "StrcturalWall.png"), UriKind.Absolute));
            pushButton.Image
=
new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "StrcturalWall-S.png"), UriKind.Absolute));

            
#endregion

            ribbonSamplePanel.AddSeparator();
        }
    }
}


AddInCommand.cs using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows.Forms;

using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;

namespace HY
{
    [Transaction(TransactionMode.Automatic)]
    [Regeneration(RegenerationOption.Manual)]
    [Journaling(JournalingMode.NoCommandData)]
   
public
class CreateWall : IExternalCommand
    {
        
public Result Execute(ExternalCommandData revit,ref
string message,ElementSet elements)
        {
            MessageBox.Show(
"创建墙");

            
return Autodesk.Revit.UI.Result.Succeeded;
        }
    }

    [Transaction(TransactionMode.Automatic)]
    [Regeneration(RegenerationOption.Manual)]
   
public
class CreateStructureWall : CreateWall
    {
    }
}


Ribbon.addin <?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
<AddIn Type="Application">
<Name>External Tool</Name>
<Assembly>F:\Ribbon\Ribbon\bin\Debug\Ribbon.dll</Assembly>
<ClientId>cb5c768a-dc2f-4289-a803-58ee5afc5708</ClientId>
<FullClassName>HY.Ribbon</FullClassName>
</AddIn>
</RevitAddIns>

作者: zj1345    时间: 2014-2-20 14:27
顶!!!!!!!!!!




欢迎光临 EaBIM (https://eabim.net/) Powered by Discuz! X3.2