EaBIM一直以来积极响应国家“十二五”推进建筑业信息化的号召,对建筑领域的信息技术开展深入技术交流和探讨!致力于打造“BIM-建筑师-生态技术”三位一体综合资源交流共享平台,希望为BIM与可持续设计理念及技术的普及做出微小的贡献!!!

EaBIM

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 928|回复: 3
打印 上一主题 下一主题

Revit启动后,如何把你的命令显示在Revit的Ribbon(工具栏)上?

[复制链接]

1514

主题

7465

帖子

1万

积分

admin

Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10

积分
12404

社区QQ达人

跳转到指定楼层
楼主
发表于 2014-1-15 14:08:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在开发的过程中,大家经常用AddinManager来运行你的外部命令,这样的好处是程序的修改,运行,调试速度可以很快。

我就此也写过一篇文章。


当你开发结束后,希望你的客户直接在Revit启动后就可以点击工具栏中的你的命令按钮,直观地使用你开发的命令。

这个过程需要一些环节来实现:


大体两种解决方案:

简单的解决方案

高级的解决方案


一. 简单方案:

     在外部命令Tab里面的外部工具下拉列表中显示你的命令名字。用户点击可以启动该命令。




   方法:制作一个插件加载文件(扩展名为addin),把这个文件放到%programdata%\autodesk\revit\addin\201* 这个目录下。

     这个文件定义了在Revit启动的时候需要加载哪些dll中的那些命令。

     详情请看这里:http://wikihelp.autodesk.com/Rev ... 00006-API_Developer

     这个方案简单易行。配置一个文件就好了。弱点是如果功能很多,组织的就不太好。用户使用起来不方案。




二. 高级方案

     在命令栏上生成你自己的按钮,     可以显示名字,图片,可以按照你希望的方式组织你所有的按钮位置和分组关系。

      实现步骤:

      1. 依然开发出你的命令

      2. 派生一个类从IExternalApplication接口派生,在这个接口的OnStartup方法里调用UIApplication类下面的方法来创建你自己的命令Tab页以及按钮,并且把按钮和你前面开发的命令绑定起来。 请看下面的完整代码。(抱歉比较长,但是提供了完整的演示过程)

     3. 制作一个加载配置文件(addin),只需要写入你的上面写的那个类(外部应用Externa Application)即可。启动后用户就会看到你用程序创建的那些按钮,点击就会运行你与之绑定的你的命令。

     4. 这个是最完美的解决方案。

  1. [csharp] view plaincopy
  2. #region Copyright  
  3. //  
  4. // Copyright (C) 2010-2012 by Autodesk, Inc.  
  5. //  
  6. // Permission to use, copy, modify, and distribute this software in  
  7. // object code form for any purpose and without fee is hereby granted,  
  8. // provided that the above copyright notice appears in all copies and  
  9. // that both that copyright notice and the limited warranty and  
  10. // restricted rights notice below appear in all supporting  
  11. // documentation.  
  12. //  
  13. // AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.  
  14. // AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF  
  15. // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.  
  16. // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE  
  17. // UNINTERRUPTED OR ERROR FREE.  
  18. //  
  19. // Use, duplication, or disclosure by the U.S. Government is subject to  
  20. // restrictions set forth in FAR 52.227-19 (Commercial Computer  
  21. // Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)  
  22. // (Rights in Technical Data and Computer Software), as applicable.  
  23. //  
  24. // Migrated to C# by Saikat Bhattacharya  
  25. //   
  26. #endregion // Copyright  

  27. #region Namespaces  
  28. using System;  
  29. using System.Collections.Generic;  
  30. using System.Diagnostics;  
  31. using System.IO;  
  32. using System.Windows.Media.Imaging;  
  33. using Autodesk.Revit.ApplicationServices;  
  34. using Autodesk.Revit.Attributes;  
  35. using Autodesk.Revit.DB;  
  36. using Autodesk.Revit.UI;  
  37. using Util;  
  38. #endregion  
  39.   
  40. namespace UiCs  
  41. {  
  42.   /// <summary>  
  43.   /// Ribbon UI.   
  44.   /// we'll be using commands we defined in Revit Intro labs. alternatively,   
  45.   /// you can use your own. Any command will do for this ribbon exercise.   
  46.   /// cf. Developer Guide, Section 3.8: Ribbon Panels and Controls. (pp 46).   
  47.   /// </summary>  
  48.   [Transaction(TransactionMode.Automatic)]  
  49.   public class UIRibbon : IExternalApplication  
  50.   {  
  51.     /// <summary>  
  52.     /// This is both the assembly name and the namespace   
  53.     /// of the external command provider.  
  54.     /// </summary>  
  55.     const string _introLabName = "IntroCs";  
  56.     const string _uiLabName = "UiCs";  
  57.     const string _dllExtension = ".dll";  
  58.   
  59.     /// <summary>  
  60.     /// Name of subdirectory containing images.  
  61.     /// </summary>  
  62.     const string _imageFolderName = "Images";  
  63.   
  64.     /// <summary>  
  65.     /// Location of managed dll where we have defined the commands.  
  66.     /// </summary>  
  67.     string _introLabPath;  
  68.   
  69.     /// <summary>  
  70.     /// Location of images for icons.  
  71.     /// </summary>  
  72.     string _imageFolder;  
  73.   
  74.     /// <summary>  
  75.     /// Starting at the given directory, search upwards for   
  76.     /// a subdirectory with the given target name located  
  77.     /// in some parent directory.   
  78.     /// </summary>  
  79.     /// <param name="path">Starting directory, e.g. GetDirectoryName( GetExecutingAssembly().Location ).</param>  
  80.     /// <param name="target">Target subdirectory name, e.g. "Images".</param>  
  81.     /// <returns>The full path of the target directory if found, else null.</returns>  
  82.     string FindFolderInParents(string path, string target)  
  83.     {  
  84.       Debug.Assert(Directory.Exists(path),  
  85.         "expected an existing directory to start search in");  
  86.   
  87.       string s;  
  88.   
  89.       do  
  90.       {  
  91.         s = Path.Combine(path, target);  
  92.         if (Directory.Exists(s))  
  93.         {  
  94.           return s;  
  95.         }  
  96.         path = Path.GetDirectoryName(path);  
  97.       } while (null != path);  
  98.   
  99.       return null;  
  100.     }  
  101.   
  102.     /// <summary>  
  103.     /// Load a new icon bitmap from our image folder.  
  104.     /// </summary>  
  105.     BitmapImage NewBitmapImage(string imageName)  
  106.     {  
  107.       return new BitmapImage(new Uri(  
  108.         Path.Combine(_imageFolder, imageName)));  
  109.     }  
  110.   
  111.     /// <summary>  
  112.     /// OnShutdown() - called when Revit ends.   
  113.     /// </summary>  
  114.     public Result OnShutdown(UIControlledApplication app)  
  115.     {  
  116.       return Result.Succeeded;  
  117.     }  
  118.   
  119.     /// <summary>  
  120.     /// OnStartup() - called when Revit starts.   
  121.     /// </summary>  
  122.     public Result OnStartup(UIControlledApplication app)  
  123.     {  
  124.       // External application directory:  
  125.   
  126.       string dir = Path.GetDirectoryName(  
  127.         System.Reflection.Assembly  
  128.         .GetExecutingAssembly().Location);  
  129.   
  130.       // External command path:  
  131.   
  132.       _introLabPath = Path.Combine(dir, _introLabName + _dllExtension);  
  133.   
  134.       if (!File.Exists(_introLabPath))  
  135.       {  
  136.         TaskDialog.Show("UIRibbon", "External command assembly not found: " + _introLabPath);  
  137.         return Result.Failed;  
  138.       }  
  139.   
  140.       // Image path:  
  141.   
  142.       _imageFolder = FindFolderInParents(dir, _imageFolderName);  
  143.   
  144.       if (null == _imageFolder  
  145.         || !Directory.Exists(_imageFolder))  
  146.       {  
  147.         TaskDialog.Show(  
  148.           "UIRibbon",  
  149.           string.Format(  
  150.             "No image folder named '{0}' found in the parent directories of '{1}.",  
  151.             _imageFolderName, dir));  
  152.   
  153.         return Result.Failed;  
  154.       }  
  155.   
  156.       // Show what kind of custom buttons and controls   
  157.       // we can add to the Add-Ins tab   
  158.   
  159.       AddRibbonSampler(app);  
  160.   
  161.       // Add one for UI Labs, too.   
  162.   
  163.       AddUILabsButtons(app);  
  164.   
  165.       return Result.Succeeded;  
  166.     }  
  167.   
  168.     /// <summary>  
  169.     /// Create our own ribbon panel with verious buttons   
  170.     /// for our exercise. We re-use commands defined in the  
  171.     /// Revit Intro Labs here. Cf. Section 3.8 (pp 46) of   
  172.     /// the Developers Guide.   
  173.     /// </summary>  
  174.     public void AddRibbonSampler(UIControlledApplication app)  
  175.     {  
  176.       // (1) create a ribbon tab and ribbon panel   
  177.   
  178.       app.CreateRibbonTab("Ribbon Sampler");  
  179.   
  180.       RibbonPanel panel = app.CreateRibbonPanel("Ribbon Sampler", "Ribbon Sampler");  
  181.   
  182.       // Below are samplers of ribbon items. Uncomment   
  183.       // functions of your interest to see how it looks like   
  184.   
  185.       // (2.1) add a simple push button for Hello World   
  186.   
  187.       AddPushButton(panel);  
  188.   
  189.       // (2.2) add split buttons for "Command Data", "DB Element" and "Element Filtering"   
  190.   
  191.       AddSplitButton(panel);  
  192.   
  193.       // (2.3) add pulldown buttons for "Command Data", "DB Element" and "Element Filtering"   
  194.   
  195.       AddPulldownButton(panel);  
  196.   
  197.       // (2.4) add radio/toggle buttons for "Command Data", "DB Element" and "Element Filtering"   
  198.       // we put it on the slide-out below.   
  199.       //AddRadioButton(panel);  
  200.       //panel.AddSeparator();  
  201.   
  202.       // (2.5) add text box - TBD: this is used with the conjunction with event. Probably too complex for day one training.   
  203.       //  for now, without event.   
  204.       // we put it on the slide-out below.   
  205.       //AddTextBox(panel);  
  206.       //panel.AddSeparator();  
  207.   
  208.       // (2.6) combo box - TBD: this is used with the conjunction with event. Probably too complex for day one training.   
  209.       // For now, without event. show two groups: Element Bascis (3 push buttons) and Modification/Creation (2 push button)   
  210.   
  211.       AddComboBox(panel);  
  212.   
  213.       // (2.7) stacked items - 1. hello world push button, 2. pulldown element bscis (command data, DB element, element filtering)   
  214.       // 3. pulldown modification/creation(element modification, model creation).   
  215.   
  216.       AddStackedButtons_Complex(panel);  
  217.   
  218.       // (2.8) slide out - if you don't have enough space, you can add additional space below the panel.   
  219.       // anything which comes after this will be on the slide out.   
  220.   
  221.       panel.AddSlideOut();  
  222.   
  223.       // (2.4) radio button - what it is   
  224.   
  225.       AddRadioButton(panel);  
  226.   
  227.       // (2.5) text box - what it is   
  228.   
  229.       AddTextBox(panel);  
  230.     }  
  231.   
  232.     /// <summary>  
  233.     /// We create our own buttons for UI Labs, too.   
  234.     /// cf. Section 3.8 (pp 46) of Developer Guide.   
  235.     /// </summary>  
  236.     public void AddUILabsButtons(UIControlledApplication app)  
  237.     {  
  238.       // Create a ribbon panel   
  239.   
  240.       RibbonPanel panel = app.CreateRibbonPanel("UI Labs");  
  241.   
  242.       // (3) adding buttons for the current labs itself.   
  243.       // You may modify this AFTER each command are defined in each lab.   
  244.       //AddUILabsCommandButtons_Template(panel) ' dummy   
  245.   
  246.       AddUILabsCommandButtons(panel);  
  247.   
  248.       // (4) This is for Lab4 event and dynamic update.   
  249.   
  250.       AddUILabsCommandButtons2(panel);  
  251.     }  
  252.   
  253.     /// <summary>  
  254.     /// Simple push button for "Hello World"   
  255.     /// </summary>  
  256.     public void AddPushButton(RibbonPanel panel)  
  257.     {  
  258.       // Set the information about the command we will be assigning to the button   
  259.   
  260.       PushButtonData pushButtonDataHello = new PushButtonData("PushButtonHello", "Hello World", _introLabPath, _introLabName + ".HelloWorld");  
  261.   
  262.       // Add a button to the panel   
  263.   
  264.       PushButton pushButtonHello = panel.AddItem(pushButtonDataHello) as PushButton;  
  265.   
  266.       // Add an icon   
  267.       // Make sure you reference WindowsBase and PresentationCore, and import System.Windows.Media.Imaging namespace.   
  268.   
  269.       pushButtonHello.LargeImage = NewBitmapImage("ImgHelloWorld.png");  
  270.   
  271.       // Add a tooltip   
  272.   
  273.       pushButtonHello.ToolTip = "simple push button";  
  274.     }  
  275.   
  276.     /// <summary>  
  277.     /// Split button for "Command Data", "DB Element" and "Element Filtering"   
  278.     /// </summary>  
  279.     public void AddSplitButton(RibbonPanel panel)  
  280.     {  
  281.       // Create three push buttons for split button drop down   
  282.   
  283.       // #1   
  284.       PushButtonData pushButtonData1 = new PushButtonData("SplitCommandData", "Command Data", _introLabPath, _introLabName + ".CommandData");  
  285.       pushButtonData1.LargeImage = NewBitmapImage("ImgHelloWorld.png");  
  286.   
  287.       // #2   
  288.       PushButtonData pushButtonData2 = new PushButtonData("SplitDbElement", "DB Element", _introLabPath, _introLabName + ".DBElement");  
  289.       pushButtonData2.LargeImage = NewBitmapImage("ImgHelloWorld.png");  
  290.   
  291.       // #3   
  292.       PushButtonData pushButtonData3 = new PushButtonData("SplitElementFiltering", "ElementFiltering", _introLabPath, _introLabName + ".ElementFiltering");  
  293.       pushButtonData3.LargeImage = NewBitmapImage("ImgHelloWorld.png");  
  294.   
  295.       // Make a split button now   
  296.       SplitButtonData splitBtnData = new SplitButtonData("SplitButton", "Split Button");  
  297.       SplitButton splitBtn = panel.AddItem(splitBtnData) as SplitButton;  
  298.       splitBtn.AddPushButton(pushButtonData1);  
  299.       splitBtn.AddPushButton(pushButtonData2);  
  300.       splitBtn.AddPushButton(pushButtonData3);  
  301.     }  
  302.   
  303.     /// <summary>  
  304.     /// Pulldown button for "Command Data", "DB Element" and "Element Filtering"  
  305.     /// </summary>  
  306.     public void AddPulldownButton(RibbonPanel panel)  
  307.     {  
  308.       // Create three push buttons for pulldown button drop down   
  309.   
  310.       // #1   
  311.       PushButtonData pushButtonData1 = new PushButtonData("PulldownCommandData", "Command Data", _introLabPath, _introLabName + ".CommandData");  
  312.       pushButtonData1.LargeImage = NewBitmapImage("Basics.ico");  
  313.   
  314.       // #2   
  315.       PushButtonData pushButtonData2 = new PushButtonData("PulldownDbElement", "DB Element", _introLabPath, _introLabName + ".DBElement");  
  316.       pushButtonData2.LargeImage = NewBitmapImage("Basics.ico");  
  317.   
  318.       // #3   
  319.       PushButtonData pushButtonData3 = new PushButtonData("PulldownElementFiltering", "Filtering", _introLabPath, _introLabName + ".ElementFiltering");  
  320.       pushButtonData3.LargeImage = NewBitmapImage("Basics.ico");  
  321.   
  322.       // Make a pulldown button now   
  323.       PulldownButtonData pulldownBtnData = new PulldownButtonData("PulldownButton", "Pulldown");  
  324.       PulldownButton pulldownBtn = panel.AddItem(pulldownBtnData) as PulldownButton;  
  325.       pulldownBtn.AddPushButton(pushButtonData1);  
  326.       pulldownBtn.AddPushButton(pushButtonData2);  
  327.       pulldownBtn.AddPushButton(pushButtonData3);  
  328.     }  
  329.   
  330.     /// <summary>  
  331.     /// Radio/toggle button for "Command Data", "DB Element" and "Element Filtering"  
  332.     /// </summary>  
  333.     public void AddRadioButton(RibbonPanel panel)  
  334.     {  
  335.       // Create three toggle buttons for radio button group   
  336.   
  337.       // #1   
  338.       ToggleButtonData toggleButtonData1 = new ToggleButtonData("RadioCommandData", "Command" + "\n Data", _introLabPath, _introLabName + ".CommandData");  
  339.       toggleButtonData1.LargeImage = NewBitmapImage("Basics.ico");  
  340.   
  341.       // #2   
  342.       ToggleButtonData toggleButtonData2 = new ToggleButtonData("RadioDbElement", "DB" + "\n Element", _introLabPath, _introLabName + ".DBElement");  
  343.       toggleButtonData2.LargeImage = NewBitmapImage("Basics.ico");  
  344.   
  345.       // #3   
  346.       ToggleButtonData toggleButtonData3 = new ToggleButtonData("RadioElementFiltering", "Filtering", _introLabPath, _introLabName + ".ElementFiltering");  
  347.       toggleButtonData3.LargeImage = NewBitmapImage("Basics.ico");  
  348.   
  349.       // Make a radio button group now   
  350.       RadioButtonGroupData radioBtnGroupData = new RadioButtonGroupData("RadioButton");  
  351.       RadioButtonGroup radioBtnGroup = panel.AddItem(radioBtnGroupData) as RadioButtonGroup;  
  352.       radioBtnGroup.AddItem(toggleButtonData1);  
  353.       radioBtnGroup.AddItem(toggleButtonData2);  
  354.       radioBtnGroup.AddItem(toggleButtonData3);  
  355.     }  
  356.   
  357.     /// <summary>  
  358.     /// Text box   
  359.     /// Text box used in conjunction with event. We'll come to this later.   
  360.     /// For now, just shows how to make a text box.   
  361.     /// </summary>  
  362.     public void AddTextBox(RibbonPanel panel)  
  363.     {  
  364.       // Fill the text box information   
  365.       TextBoxData txtBoxData = new TextBoxData("TextBox");  
  366.       txtBoxData.Image = NewBitmapImage("Basics.ico");  
  367.       txtBoxData.Name = "Text Box";  
  368.       txtBoxData.ToolTip = "Enter text here";  
  369.       txtBoxData.LongDescription = "<p>This is Revit UI Labs.</p><p>Ribbon Lab</p>";  
  370.       txtBoxData.ToolTipImage = NewBitmapImage("ImgHelloWorld.png");  
  371.   
  372.       // Create the text box item on the panel   
  373.       TextBox txtBox = panel.AddItem(txtBoxData) as TextBox;  
  374.       txtBox.PromptText = "Enter a comment";  
  375.       txtBox.ShowImageAsButton = true;  
  376.   
  377.       txtBox.EnterPressed += new EventHandler<Autodesk.Revit.UI.Events.TextBoxEnterPressedEventArgs>(txtBox_EnterPressed);  
  378.       txtBox.Width = 180;  
  379.     }  
  380.   
  381.     /// <summary>  
  382.     /// Event handler for the above text box   
  383.     /// </summary>  
  384.     void txtBox_EnterPressed(object sender, Autodesk.Revit.UI.Events.TextBoxEnterPressedEventArgs e)  
  385.     {  
  386.       // Cast sender to TextBox to retrieve text value  
  387.       TextBox textBox = sender as TextBox;  
  388.       TaskDialog.Show("TextBox Input", "This is what you typed in: " + textBox.Value.ToString());  
  389.     }  
  390.   
  391.     /// <summary>  
  392.     /// Combo box - 5 items in 2 groups.   
  393.     /// Combo box is used in conjunction with event. We'll come back later.   
  394.     /// For now, just demonstrates how to make a combo box.   
  395.     /// </summary>  
  396.     public void AddComboBox(RibbonPanel panel)  
  397.     {  
  398.       // Create five combo box members with two groups   
  399.   
  400.       // #1   
  401.       ComboBoxMemberData comboBoxMemberData1 = new ComboBoxMemberData("ComboCommandData", "Command Data");  
  402.       comboBoxMemberData1.Image = NewBitmapImage("Basics.ico");  
  403.       comboBoxMemberData1.GroupName = "DB Basics";  
  404.   
  405.       // #2   
  406.       ComboBoxMemberData comboBoxMemberData2 = new ComboBoxMemberData("ComboDbElement", "DB Element");  
  407.       comboBoxMemberData2.Image = NewBitmapImage("Basics.ico");  
  408.       comboBoxMemberData2.GroupName = "DB Basics";  
  409.   
  410.       // #3   
  411.       ComboBoxMemberData comboBoxMemberData3 = new ComboBoxMemberData("ComboElementFiltering", "Filtering");  
  412.       comboBoxMemberData3.Image = NewBitmapImage("Basics.ico");  
  413.       comboBoxMemberData3.GroupName = "DB Basics";  
  414.   
  415.       // #4   
  416.       ComboBoxMemberData comboBoxMemberData4 = new ComboBoxMemberData("ComboElementModification", "Modify");  
  417.       comboBoxMemberData4.Image = NewBitmapImage("Basics.ico");  
  418.       comboBoxMemberData4.GroupName = "Modeling";  
  419.   
  420.       // #5   
  421.       ComboBoxMemberData comboBoxMemberData5 = new ComboBoxMemberData("ComboModelCreation", "Create");  
  422.       comboBoxMemberData5.Image = NewBitmapImage("Basics.ico");  
  423.       comboBoxMemberData5.GroupName = "Modeling";  
  424.   
  425.       // Make a combo box now   
  426.       ComboBoxData comboBxData = new ComboBoxData("ComboBox");  
  427.       ComboBox comboBx = panel.AddItem(comboBxData) as ComboBox;  
  428.       comboBx.ToolTip = "Select an Option";  
  429.       comboBx.LongDescription = "select a command you want to run";  
  430.       comboBx.AddItem(comboBoxMemberData1);  
  431.       comboBx.AddItem(comboBoxMemberData2);  
  432.       comboBx.AddItem(comboBoxMemberData3);  
  433.       comboBx.AddItem(comboBoxMemberData4);  
  434.       comboBx.AddItem(comboBoxMemberData5);  
  435.   
  436.       comboBx.CurrentChanged += new EventHandler<Autodesk.Revit.UI.Events.ComboBoxCurrentChangedEventArgs>(comboBx_CurrentChanged);  
  437.     }  
  438.   
  439.     /// <summary>  
  440.     /// Event handler for the above combo box   
  441.     /// </summary>      
  442.     void comboBx_CurrentChanged(object sender, Autodesk.Revit.UI.Events.ComboBoxCurrentChangedEventArgs e)  
  443.     {  
  444.       // Cast sender as TextBox to retrieve text value  
  445.       ComboBox combodata = sender as ComboBox;  
  446.       ComboBoxMember member = combodata.Current;  
  447.       TaskDialog.Show("Combobox Selection", "Your new selection: " + member.ItemText);  
  448.     }  
  449.   
  450.     /// <summary>  
  451.     /// Stacked Buttons - combination of: push button, dropdown button, combo box and text box.   
  452.     /// (no radio button group, split buttons).   
  453.     /// Here we stack three push buttons for "Command Data", "DB Element" and "Element Filtering".   
  454.     /// </summary>  
  455.     public void AddStackedButtons_Simple(RibbonPanel panel)  
  456.     {  
  457.       // Create three push buttons to stack up   
  458.       // #1   
  459.       PushButtonData pushButtonData1 = new PushButtonData("StackSimpleCommandData", "Command Data", _introLabPath, _introLabName + ".CommandData");  
  460.       pushButtonData1.Image = NewBitmapImage("ImgHelloWorldSmall.png");  
  461.   
  462.       // #2   
  463.       PushButtonData pushButtonData2 = new PushButtonData("StackSimpleDbElement", "DB Element", _introLabPath, _introLabName + ".DBElement");  
  464.       pushButtonData2.Image = NewBitmapImage("ImgHelloWorldSmall.png");  
  465.   
  466.       // #3   
  467.       PushButtonData pushButtonData3 = new PushButtonData("StackSimpleElementFiltering", "Element Filtering", _introLabPath, _introLabName + ".ElementFiltering");  
  468.       pushButtonData3.Image = NewBitmapImage("ImgHelloWorldSmall.png");  
  469.   
  470.       // Put them on stack   
  471.       IList<RibbonItem> stackedButtons = panel.AddStackedItems(pushButtonData1, pushButtonData2, pushButtonData3);  
  472.     }  
  473.   
  474.     /// <summary>  
  475.     /// Stacked Buttons - combination of: push button, dropdown button, combo box and text box.   
  476.     /// (no radio button group, split buttons).   
  477.     /// Here we define 6 buttons, make grouping of 1, 3, 2 items, and stack them in three layer:   
  478.     /// (1) simple push button with "Hello World"   
  479.     /// (2) pull down with 3 items: "Command Data", "DB Element" and "Element Filtering".   
  480.     /// (3) pull down with 2 items: "Element Modification" and "Model Creation"   
  481.     /// </summary>  
  482.     public void AddStackedButtons_Complex(RibbonPanel panel)  
  483.     {  
  484.       // Create six push buttons to group for pull down and stack up   
  485.   
  486.       // #0   
  487.       PushButtonData pushButtonData0 = new PushButtonData("StackComplexHelloWorld", "Hello World", _introLabPath, _introLabName + ".HelloWorld");  
  488.       pushButtonData0.Image = NewBitmapImage("Basics.ico");  
  489.   
  490.       // #1   
  491.       PushButtonData pushButtonData1 = new PushButtonData("StackComplexCommandData", "Command Data", _introLabPath, _introLabName + ".CommandData");  
  492.       pushButtonData1.Image = NewBitmapImage("Basics.ico");  
  493.   
  494.       // #2   
  495.       PushButtonData pushButtonData2 = new PushButtonData("StackComplexDbElement", "DB Element", _introLabPath, _introLabName + ".DBElement");  
  496.   
  497.       // #3   
  498.       PushButtonData pushButtonData3 = new PushButtonData("StackComplexElementFiltering", "Filtering", _introLabPath, _introLabName + ".ElementFiltering");  
  499.   
  500.       // #4   
  501.       PushButtonData pushButtonData4 = new PushButtonData("StackComplexElementModification", "Modify", _introLabPath, _introLabName + ".ElementModification");  
  502.   
  503.       // #5   
  504.       PushButtonData pushButtonData5 = new PushButtonData("StackComplexModelCreation", "Create", _introLabPath, _introLabName + ".ModelCreation");  
  505.   
  506.       // Make two sets of pull down   
  507.   
  508.       PulldownButtonData pulldownBtnData1 = new PulldownButtonData("StackComplePulldownButton1", "DB Basics");  
  509.       PulldownButtonData pulldownBtnData2 = new PulldownButtonData("StackComplePulldownButton2", "Modeling");  
  510.   
  511.       // Create three item stack.   
  512.       IList<RibbonItem> stackedItems = panel.AddStackedItems(pushButtonData0, pulldownBtnData1, pulldownBtnData2);  
  513.       PulldownButton pulldownBtn2 = stackedItems[1] as PulldownButton;  
  514.       PulldownButton pulldownBtn3 = stackedItems[2] as PulldownButton;  
  515.   
  516.       pulldownBtn2.Image = NewBitmapImage("Basics.ico");  
  517.       pulldownBtn3.Image = NewBitmapImage("House.ico");  
  518.   
  519.       // Add each sub items   
  520.       PushButton button1 = pulldownBtn2.AddPushButton(pushButtonData1);  
  521.       PushButton button2 = pulldownBtn2.AddPushButton(pushButtonData2);  
  522.       PushButton button3 = pulldownBtn2.AddPushButton(pushButtonData3);  
  523.       PushButton button4 = pulldownBtn3.AddPushButton(pushButtonData4);  
  524.       PushButton button5 = pulldownBtn3.AddPushButton(pushButtonData5);  
  525.   
  526.       // Note: we need to set the image later. if we do in button data, it won't show in the Ribbon.   
  527.       button1.Image = NewBitmapImage("Basics.ico");  
  528.       button2.Image = NewBitmapImage("Basics.ico");  
  529.       button3.Image = NewBitmapImage("Basics.ico");  
  530.       button4.Image = NewBitmapImage("Basics.ico");  
  531.   
  532.       button5.Image = NewBitmapImage("Basics.ico");  
  533.     }  
  534.   
  535.     /// <summary>  
  536.     /// Add buttons for the commands we define in this labs.   
  537.     /// Here we stack three push buttons and repeat it as we get more.   
  538.     /// This is a template to use during the Ribbon lab exercise prior to going to following labs.   
  539.     /// </summary>  
  540.     public void AddUILabsCommandButtons_Template(RibbonPanel panel)  
  541.     {  
  542.       // Get the location of this dll.   
  543.       string assembly = GetType().Assembly.Location;  
  544.   
  545.       // Create three push buttons to stack up   
  546.       // #1   
  547.       PushButtonData pushButtonData1 = new PushButtonData("UILabsCommand1", "Command1", assembly, _uiLabName + ".Command1");  
  548.       pushButtonData1.Image = NewBitmapImage("ImgHelloWorldSmall.png");  
  549.   
  550.       // #2   
  551.       PushButtonData pushButtonData2 = new PushButtonData("UILabsCommand2", "Command2", assembly, _uiLabName + ".Command2");  
  552.       pushButtonData2.Image = NewBitmapImage("ImgHelloWorldSmall.png");  
  553.   
  554.       // #3   
  555.       PushButtonData pushButtonData3 = new PushButtonData("UILabsCommand3", "Command3", assembly, _uiLabName + ".Command3");  
  556.       pushButtonData3.Image = NewBitmapImage("ImgHelloWorldSmall.png");  
  557.   
  558.       // Put them on stack   
  559.   
  560.       IList<RibbonItem> stackedButtons = panel.AddStackedItems(pushButtonData1, pushButtonData2, pushButtonData3);  
  561.     }  
  562.   
  563.     /// <summary>  
  564.     /// Add buttons for the commands we define in this labs.   
  565.     /// Here we stack three push buttons and repeat it as we get more.   
  566.     /// </summary>  
  567.     public void AddUILabsCommandButtons(RibbonPanel panel)  
  568.     {  
  569.       // Get the location of this dll.   
  570.       string assembly = GetType().Assembly.Location;  
  571.   
  572.       // Create three push buttons to stack up   
  573.       // #1   
  574.       PushButtonData pushButtonData1 = new PushButtonData("UILabsSelection", "Pick Sampler", assembly, _uiLabName + ".UISelection");  
  575.       pushButtonData1.Image = NewBitmapImage("basics.ico");  
  576.   
  577.       // #2   
  578.       PushButtonData pushButtonData2 = new PushButtonData("UILabsCreateHouse", "Create House Pick", assembly, _uiLabName + ".UICreateHouse");  
  579.       pushButtonData2.Image = NewBitmapImage("House.ico");  
  580.   
  581.       // #3   
  582.       PushButtonData pushButtonData3 = new PushButtonData("UILabsTaskDialog", "Dialog Sampler", assembly, _uiLabName + ".UITaskDialog");  
  583.       pushButtonData3.Image = NewBitmapImage("basics.ico");  
  584.   
  585.       // #4   
  586.       PushButtonData pushButtonData4 = new PushButtonData("UILabsCreateHouseDialog", "Create House Dialog", assembly, _uiLabName + ".UICreateHouseDialog");  
  587.       pushButtonData4.Image = NewBitmapImage("House.ico");  
  588.   
  589.       // #5   
  590.       // Make three sets of pull down   
  591.       PulldownButtonData pulldownBtnData1 = new PulldownButtonData("UILabsPulldownButton1", "Selection");  
  592.       PulldownButtonData pulldownBtnData2 = new PulldownButtonData("UILabsPulldownButton2", "Task Dialog");  
  593.   
  594.       // Create three item stack.   
  595.       IList<RibbonItem> stackedItems = panel.AddStackedItems(pulldownBtnData1, pulldownBtnData2);  
  596.       PulldownButton pulldownBtn1 = stackedItems[0] as PulldownButton;  
  597.       PulldownButton pulldownBtn2 = stackedItems[1] as PulldownButton;  
  598.   
  599.       pulldownBtn1.Image = NewBitmapImage("Basics.ico");  
  600.       pulldownBtn2.Image = NewBitmapImage("Basics.ico");  
  601.   
  602.       // Add each sub items   
  603.       PushButton button1 = pulldownBtn1.AddPushButton(pushButtonData1);  
  604.       PushButton button2 = pulldownBtn1.AddPushButton(pushButtonData2);  
  605.       PushButton button3 = pulldownBtn2.AddPushButton(pushButtonData3);  
  606.       PushButton button4 = pulldownBtn2.AddPushButton(pushButtonData4);  
  607.   
  608.       // Note: we need to set the image later. if we do in button data, it won't show in the Ribbon.   
  609.       button1.Image = NewBitmapImage("Basics.ico");  
  610.       button2.Image = NewBitmapImage("Basics.ico");  
  611.       button3.Image = NewBitmapImage("Basics.ico");  
  612.       button4.Image = NewBitmapImage("Basics.ico");  
  613.     }  
  614.   
  615.     /// <summary>  
  616.     /// Add buttons for the commands we define in this labs.   
  617.     /// Here we stack 2 x 2-push buttons and repeat it as we get more.   
  618.     /// TBD: still thinking which version is better ...   
  619.     /// </summary>  
  620.     public void AddUILabsCommandButtons_v2(RibbonPanel panel)  
  621.     {  
  622.       // Get the location of this dll.   
  623.       string assembly = GetType().Assembly.Location;  
  624.   
  625.       // Create push buttons to stack up   
  626.       // #1   
  627.       PushButtonData pushButtonData1 = new PushButtonData("UILabsSelection", "Pick Sampler", assembly, _uiLabName + ".UISelection");  
  628.       pushButtonData1.Image = NewBitmapImage("basics.ico");  
  629.   
  630.       // #2   
  631.       PushButtonData pushButtonData2 = new PushButtonData("UILabsCreateHouseUI", "Create House Pick", assembly, _uiLabName + ".CreateHouseUI");  
  632.       pushButtonData2.Image = NewBitmapImage("basics.ico");  
  633.   
  634.       // #3   
  635.       PushButtonData pushButtonData3 = new PushButtonData("UILabsTaskDialog", "Dialog Sampler", assembly, _uiLabName + ".UITaskDialog");  
  636.       pushButtonData3.Image = NewBitmapImage("basics.ico");  
  637.   
  638.       // #4   
  639.       PushButtonData pushButtonData4 = new PushButtonData("UILabsCreateHouseDialog", "Create House Dialog", assembly, _uiLabName + ".CreateHouseDialog");  
  640.       pushButtonData4.Image = NewBitmapImage("basics.ico");  
  641.   
  642.       // Create 2 x 2-item stack.   
  643.       IList<RibbonItem> stackedItems1 = panel.AddStackedItems(pushButtonData1, pushButtonData2);  
  644.   
  645.       IList<RibbonItem> stackedItems2 = panel.AddStackedItems(pushButtonData3, pushButtonData4);  
  646.     }  
  647.   
  648.     /// <summary>  
  649.     /// Control buttons for Event and Dynamic Model Update   
  650.     /// </summary>  
  651.     public void AddUILabsCommandButtons2(RibbonPanel panel)  
  652.     {  
  653.       // Get the location of this dll.   
  654.       string assembly = GetType().Assembly.Location;  
  655.   
  656.       // Create three toggle buttons for radio button group   
  657.       // #1   
  658.       ToggleButtonData toggleButtonData1 = new ToggleButtonData("UILabsEventOn", "Event" + "\n Off", assembly, _uiLabName + ".UIEventOff");  
  659.       toggleButtonData1.LargeImage = NewBitmapImage("Basics.ico");  
  660.   
  661.       // #2   
  662.       ToggleButtonData toggleButtonData2 = new ToggleButtonData("UILabsEventOff", "Event" + "\n On", assembly, _uiLabName + ".UIEventOn");  
  663.       toggleButtonData2.LargeImage = NewBitmapImage("Basics.ico");  
  664.   
  665.       // Create three toggle buttons for radio button group   
  666.       // #3   
  667.       ToggleButtonData toggleButtonData3 = new ToggleButtonData("UILabsDynUpdateOn", "Center" + "\n Off", assembly, _uiLabName + ".UIDynamicModelUpdateOff");  
  668.       toggleButtonData3.LargeImage = NewBitmapImage("Families.ico");  
  669.   
  670.       // #4   
  671.       ToggleButtonData toggleButtonData4 = new ToggleButtonData("UILabsDynUpdateOff", "Center" + "\n On", assembly, _uiLabName + ".UIDynamicModelUpdateOn");  
  672.       toggleButtonData4.LargeImage = NewBitmapImage("Families.ico");  
  673.   
  674.       // Make event pn/off radio button group   
  675.       RadioButtonGroupData radioBtnGroupData1 = new RadioButtonGroupData("EventNotification");  
  676.       RadioButtonGroup radioBtnGroup1 = panel.AddItem(radioBtnGroupData1) as RadioButtonGroup;  
  677.       radioBtnGroup1.AddItem(toggleButtonData1);  
  678.       radioBtnGroup1.AddItem(toggleButtonData2);  
  679.   
  680.       // Make dyn update on/off radio button group   
  681.       RadioButtonGroupData radioBtnGroupData2 = new RadioButtonGroupData("WindowDoorCenter");  
  682.       RadioButtonGroup radioBtnGroup2 = panel.AddItem(radioBtnGroupData2) as RadioButtonGroup;  
  683.       radioBtnGroup2.AddItem(toggleButtonData3);  
  684.   
  685.       radioBtnGroup2.AddItem(toggleButtonData4);  
  686.     }  
  687.   }  

  688.   #region Helper Classes  
  689.   /// <summary>  
  690.   /// This lab uses Revit Intro Labs.   
  691.   /// If you prefer to use a dummy command instead, you can do so.   
  692.   /// Providing a command template here.   
  693.   /// </summary>  
  694.   [Transaction(TransactionMode.Automatic)]  
  695.   public class DummyCommand1 : IExternalCommand  
  696.   {  
  697.     public Result Execute(  
  698.       ExternalCommandData commandData,  
  699.       ref string message,  
  700.       ElementSet elements)  
  701.     {  
  702.       // Write your command implementation here   
  703.   
  704.       TaskDialog.Show("Dummy command", "You have called Command1");  
  705.   
  706.       return Result.Succeeded;  
  707.     }  
  708.   }  
  709.   #endregion  
  710. }  
复制代码
转载请复制以下信息:
原文链接: http://blog.csdn.net/joexiongjin/article/details/8182889
作者:  叶雄进 , Autodesk ADN

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 转播转播 分享分享 分享淘帖 支持支持 反对反对

相关帖子

工作时间:工作日的9:00-12:00/13:30-18:00,节假日不在线,请勿留言

12

主题

899

帖子

1638

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1638
2F
发表于 2014-2-13 10:19:55 | 只看该作者
看的晕了 还是感谢楼主的分享

4

主题

851

帖子

1307

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1307
4F
发表于 2014-2-20 14:07:34 | 只看该作者
顶...... 楼下跟上.....
*滑块验证:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|EaBIM网 ( 苏ICP备2020058923号-1  苏公网安备32011502011255号

GMT+8, 2024-11-16 16:31

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表