MenuConfig.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. 
  2. /* ==============================================================================
  3. * 功能描述:启动Revit时自定义菜单配置
  4. * 创 建 者:SAGACLOUD
  5. * 创建日期:2017/8/30
  6. * ==============================================================================*/
  7. using Autodesk.Revit.UI;
  8. using SAGA.DotNetUtils;
  9. using SAGA.RevitUtils;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Windows.Media.Imaging;
  15. using System.Xml;
  16. using Autodesk.Windows;
  17. using SAGA.DotNetUtils.Extend;
  18. using SAGA.DotNetUtils.Others;
  19. using SAGA.RevitMenu.Addin;
  20. using RibbonItem = Autodesk.Revit.UI.RibbonItem;
  21. using RibbonPanel = Autodesk.Revit.UI.RibbonPanel;
  22. namespace SAGA.RevitMenu.Configuration
  23. {
  24. public class MenuConfig
  25. {
  26. /// <summary>
  27. /// 加载菜单
  28. /// </summary>
  29. /// <param name="application"></param>
  30. /// <returns></returns>
  31. public static bool LoadMenus(UIControlledApplication application)
  32. {
  33. try
  34. {
  35. if (application.ActiveAddInId == null)
  36. {
  37. return false;
  38. }
  39. Guid gUID = application.ActiveAddInId.GetGUID();
  40. string str = "";
  41. if (gUID.ToString().ToUpper() == "EABBE53F-04A0-4D10-905F-FE4DB67E1F3C")
  42. {
  43. str = "TSBIM";
  44. }
  45. if (str.Length == 0)
  46. {
  47. return false;
  48. }
  49. bool blnRevit = false;
  50. TszTabData[] configTabs = XmlMenuData.GetConfigTabs(application.ControlledApplication.VersionNumber, out blnRevit);
  51. if ((configTabs == null) || (configTabs.Length <= 0))
  52. {
  53. MessageShow.Infomation("菜单加载错误:菜单配置文件异常");
  54. return false;
  55. }
  56. //跟据权限对数据进行修饰
  57. //XmlMenuDataWrapper.Wrapper(configTabs);
  58. bool flag2 = RevitRibbonOperate.ApplyConfigTabs(application, configTabs);
  59. return flag2;
  60. }
  61. catch (Exception exception)
  62. {
  63. if (exception.Message == "Too many tabs have been created by the API. Instead, you may add your Ribbon Panels to the Add-Ins tab.")
  64. {
  65. MessageShow.Infomation("启动的插件菜单过多,请勿全部勾选或卸载其它插件。");
  66. }
  67. else
  68. {
  69. MessageShow.Show(exception, false, "");
  70. }
  71. return false;
  72. }
  73. }
  74. /// <summary>
  75. /// 清除Addins文件
  76. /// </summary>
  77. /// <param name="application"></param>
  78. /// <returns></returns>
  79. public static bool ClearAddInFile(UIControlledApplication application)
  80. {
  81. if (application.ActiveAddInId == null)
  82. {
  83. return false;
  84. }
  85. Guid guid = application.ActiveAddInId.GetGUID();
  86. string strProductType = application.ControlledApplication.Product.ToString();
  87. string versionNumber = application.ControlledApplication.VersionNumber;
  88. return RevitStartHelper.ClearAddInFile(guid, strProductType, versionNumber);
  89. }
  90. }
  91. }