XHApplication.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:XHApplication
  3. * 作者:xulisong
  4. * 创建时间: 2019/1/16 17:26:49
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Reflection;
  12. using System.Text;
  13. using Autodesk.Revit.DB;
  14. using Autodesk.Revit.UI;
  15. using FWindSoft.Revit;
  16. using FWindSoft.Revit.ExtensibleStorage;
  17. using FWindSoft.Revit.Menu;
  18. using FWindSoft.Wpf;
  19. namespace LRH.RevitApplication
  20. {
  21. public class XHApplication: ExternalApplication
  22. {
  23. protected override void AttachExecute(UIControlledApplication application)
  24. {
  25. //DockableWindow win = new DockableWindow();
  26. //win.RegisterDockableWindow(CurrentApp.UIControlApp, RevitCustomDockablePanels.Default);
  27. CatchUnhandledException();
  28. //MessageTip.Show("启动");
  29. //var paneId = DockablePanes.BuiltInDockablePanes.PropertiesPalette;
  30. //DockablePane pane = application.GetDockablePane(paneId);
  31. //var cc=pane.GetTitle();
  32. //var cc1 = pane.IsShown();
  33. //pane.Hide();
  34. MenuConfig config = InitMenu();
  35. if (config != null)
  36. {
  37. config.CreateUIRibbion(application);
  38. }
  39. //Delegate[] delArray = this.UIControlApp.ControlledApplication.FamilyLoadedIntoDocument.GetInvocationList();
  40. //this.UIControlApp.ControlledApplication.FamilyLoadedIntoDocument = null;
  41. //DockablePane.
  42. // pane.pro
  43. //var useEvent = typeof(ControlledApplication).GetEvent("FamilyLoadedIntoDocument");
  44. //var fileds = useEvent.DeclaringType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase | BindingFlags.Static);
  45. //var filed= useEvent.DeclaringType.GetField(typeof(ControlledApplication).FullName+ "FamilyLoadedIntoDocument",BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase | BindingFlags.Static);
  46. //if (filed != null)
  47. //{
  48. // fileds[0].SetValue(this.UIControlApp.ControlledApplication, null);
  49. //
  50. //this.UIControlApp.ControlledApplication.FamilyLoadedIntoDocument += ControlledApplication_FamilyLoadedIntoDocument;
  51. //this.UIControlApp.ControlledApplication.FamilyLoadingIntoDocument += ControlledApplication_FamilyLoadingIntoDocument;
  52. }
  53. private object m_obj = new object();
  54. private void ControlledApplication_FamilyLoadingIntoDocument(object sender, Autodesk.Revit.DB.Events.FamilyLoadingIntoDocumentEventArgs e)
  55. {
  56. MessageTip.Show("loading");
  57. //Monitor.Enter(m_obj);
  58. try
  59. {
  60. var usePath = Path.Combine(e.FamilyPath, e.FamilyName + ".rfa");
  61. var document = e.Document.Application.OpenDocumentFile(usePath);
  62. if (!document.IsFamilyDocument)
  63. {
  64. return;
  65. }
  66. var family = document.OwnerFamily;//.GetElements<Family>()?.FirstOrDefault();
  67. if (family != null)
  68. {
  69. family.DeleteStorageData(Guid.Parse("1f88140c-b84a-4c6b-a998-722d1173200f"));
  70. // document.Save();
  71. }
  72. }
  73. catch (Exception ex)
  74. {
  75. MessageTip.Show(ex.ToString()+"\n\r"+ex.StackTrace.ToString());
  76. }
  77. //e.Cancel();
  78. }
  79. private void ControlledApplication_FamilyLoadedIntoDocument(object sender, Autodesk.Revit.DB.Events.FamilyLoadedIntoDocumentEventArgs e)
  80. {
  81. #region 信息
  82. MessageTip.Show("Loaded");
  83. try
  84. {
  85. //BindingFlags mPropertyFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic;
  86. //BindingFlags mFieldFlags = BindingFlags.Static | BindingFlags.NonPublic;
  87. e.Document.GetElement(e.NewFamilyId).DeleteStorageData(Guid.Parse("1f88140c-b84a-4c6b-a998-722d1173200f"));
  88. }
  89. catch (Exception ex)
  90. {
  91. }
  92. //Monitor.Exit(m_obj);
  93. #endregion
  94. }
  95. protected override void ShutExecute(UIControlledApplication application)
  96. {
  97. base.ShutExecute(application);
  98. NoCatchUnhandledException();
  99. this.UIControlApp.ControlledApplication.FamilyLoadedIntoDocument -= ControlledApplication_FamilyLoadedIntoDocument;
  100. }
  101. private MenuConfig InitMenu()
  102. {
  103. var assemblyName1 = Assembly.GetExecutingAssembly().Location;
  104. return ButtonAssemblyManager.GetMenuConfig(Path.GetDirectoryName(assemblyName1));
  105. MenuConfig config;
  106. //using (Stream xmlSteam = Assembly.GetExecutingAssembly().GetManifestResourceStream("LRH.RevitApplication.Tool.xml"))
  107. //{
  108. // config = MenuConfigParser.Load(xmlSteam);
  109. //}
  110. //var dorectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  111. //config.Buttons.ToList().ForEach(b => b.AssemblyName = Path.Combine(dorectory, b.AssemblyName));
  112. //return config;
  113. config = new MenuConfig();
  114. //config.Tabs.Add(new RevitTab() { Name = "tab1", Text = "tab1" });
  115. config.Tabs.Add(new RevitTab() { Name = "tab2", Text = "tab2" });
  116. //config.Panels.Add(new RevitPanel() { Name = "panel1", Text = "panel1", TabName = "tab1" });
  117. config.Panels.Add(new RevitPanel() { Name = "panel2", Text = "panel2", TabName = "tab2" });
  118. //config.Panels.Add(new RevitPanel() { Name = "panel3", Text = "panel3", TabName = "tab2" });
  119. //config.Panels.Add(new RevitPanel() { Name = "panel4", Text = "panel4", TabName = "tab2" });
  120. var assemblyName = Assembly.GetExecutingAssembly().Location;
  121. var newAssembly = Path.Combine(Path.GetDirectoryName(assemblyName), "LRH.Tool.dll");
  122. var newAssembly2 = Path.Combine(Path.GetDirectoryName(assemblyName), "FWindSoft.Revit.dll");
  123. //config.Buttons.Add(new RevitButton() { PanelName = "panel1", Name = "button1", Text = "button1", AssemblyName = newAssembly, ClassName = "LRH.Tool.CreateBallFlagCommand", ButtonStyle = RevitButtonStyle.Push, IsStack = true });
  124. //config.Buttons.Add(new RevitButton() { PanelName = "panel1", Name = "button2", Text = "button2", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Push, IsStack = true });
  125. //config.Buttons.Add(new RevitButton() { PanelName = "panel1", Name = "button3", Text = "button3", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Push, IsStack = true });
  126. //config.Buttons.Add(new RevitButton() { PanelName = "panel1", Name = "button4", Text = "button4", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Push });
  127. //config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button1", Text = "button1", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Push });
  128. //config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button2", Text = "button2", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Push });
  129. //config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button3", Text = "button3", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Push });
  130. //config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button4", Text = "button4", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Separator });
  131. config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "cc", Text = "导出", AssemblyName = newAssembly, ClassName = "LRH.Tool.ExportDocumentToDwg3", ButtonStyle = RevitButtonStyle.Pulldown, IsStack = true });
  132. config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button5", Text = "导出dwg", AssemblyName = newAssembly, ClassName = "LRH.Tool.ExportDocumentToDwg", ButtonStyle = RevitButtonStyle.Pulldown });
  133. config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button6", Text = "button6", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Pulldown });
  134. config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button51", Text = "button51", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand",GroupName="AA" ,ButtonStyle = RevitButtonStyle.Pulldown,IsStack=true});
  135. config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button61", Text = "button61", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", GroupName = "AA", ButtonStyle = RevitButtonStyle.Pulldown });
  136. config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button7", Text = "button7", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Split, IsStack = true });
  137. config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button8", Text = "button8", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Split });
  138. return config;
  139. }
  140. }
  141. }