MenuConfig.cs 3.4 KB

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