/*------------------------------------------------------------------------- * 功能描述:XHApplication * 作者:xulisong * 创建时间: 2019/1/16 17:26:49 * 版本号:v1.0 * -------------------------------------------------------------------------*/ using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using FWindSoft.Revit; using FWindSoft.Revit.ExtensibleStorage; using FWindSoft.Revit.Menu; using FWindSoft.Wpf; namespace LRH.RevitApplication { public class XHApplication: ExternalApplication { protected override void AttachExecute(UIControlledApplication application) { //DockableWindow win = new DockableWindow(); //win.RegisterDockableWindow(CurrentApp.UIControlApp, RevitCustomDockablePanels.Default); CatchUnhandledException(); //MessageTip.Show("启动"); //var paneId = DockablePanes.BuiltInDockablePanes.PropertiesPalette; //DockablePane pane = application.GetDockablePane(paneId); //var cc=pane.GetTitle(); //var cc1 = pane.IsShown(); //pane.Hide(); MenuConfig config = InitMenu(); if (config != null) { config.CreateUIRibbion(application); } //Delegate[] delArray = this.UIControlApp.ControlledApplication.FamilyLoadedIntoDocument.GetInvocationList(); //this.UIControlApp.ControlledApplication.FamilyLoadedIntoDocument = null; //DockablePane. // pane.pro //var useEvent = typeof(ControlledApplication).GetEvent("FamilyLoadedIntoDocument"); //var fileds = useEvent.DeclaringType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase | BindingFlags.Static); //var filed= useEvent.DeclaringType.GetField(typeof(ControlledApplication).FullName+ "FamilyLoadedIntoDocument",BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase | BindingFlags.Static); //if (filed != null) //{ // fileds[0].SetValue(this.UIControlApp.ControlledApplication, null); // //this.UIControlApp.ControlledApplication.FamilyLoadedIntoDocument += ControlledApplication_FamilyLoadedIntoDocument; //this.UIControlApp.ControlledApplication.FamilyLoadingIntoDocument += ControlledApplication_FamilyLoadingIntoDocument; } private object m_obj = new object(); private void ControlledApplication_FamilyLoadingIntoDocument(object sender, Autodesk.Revit.DB.Events.FamilyLoadingIntoDocumentEventArgs e) { MessageTip.Show("loading"); //Monitor.Enter(m_obj); try { var usePath = Path.Combine(e.FamilyPath, e.FamilyName + ".rfa"); var document = e.Document.Application.OpenDocumentFile(usePath); if (!document.IsFamilyDocument) { return; } var family = document.OwnerFamily;//.GetElements()?.FirstOrDefault(); if (family != null) { family.DeleteStorageData(Guid.Parse("1f88140c-b84a-4c6b-a998-722d1173200f")); // document.Save(); } } catch (Exception ex) { MessageTip.Show(ex.ToString()+"\n\r"+ex.StackTrace.ToString()); } //e.Cancel(); } private void ControlledApplication_FamilyLoadedIntoDocument(object sender, Autodesk.Revit.DB.Events.FamilyLoadedIntoDocumentEventArgs e) { #region 信息 MessageTip.Show("Loaded"); try { //BindingFlags mPropertyFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic; //BindingFlags mFieldFlags = BindingFlags.Static | BindingFlags.NonPublic; e.Document.GetElement(e.NewFamilyId).DeleteStorageData(Guid.Parse("1f88140c-b84a-4c6b-a998-722d1173200f")); } catch (Exception ex) { } //Monitor.Exit(m_obj); #endregion } protected override void ShutExecute(UIControlledApplication application) { base.ShutExecute(application); NoCatchUnhandledException(); this.UIControlApp.ControlledApplication.FamilyLoadedIntoDocument -= ControlledApplication_FamilyLoadedIntoDocument; } private MenuConfig InitMenu() { var assemblyName1 = Assembly.GetExecutingAssembly().Location; return ButtonAssemblyManager.GetMenuConfig(Path.GetDirectoryName(assemblyName1)); MenuConfig config; //using (Stream xmlSteam = Assembly.GetExecutingAssembly().GetManifestResourceStream("LRH.RevitApplication.Tool.xml")) //{ // config = MenuConfigParser.Load(xmlSteam); //} //var dorectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); //config.Buttons.ToList().ForEach(b => b.AssemblyName = Path.Combine(dorectory, b.AssemblyName)); //return config; config = new MenuConfig(); //config.Tabs.Add(new RevitTab() { Name = "tab1", Text = "tab1" }); config.Tabs.Add(new RevitTab() { Name = "tab2", Text = "tab2" }); //config.Panels.Add(new RevitPanel() { Name = "panel1", Text = "panel1", TabName = "tab1" }); config.Panels.Add(new RevitPanel() { Name = "panel2", Text = "panel2", TabName = "tab2" }); //config.Panels.Add(new RevitPanel() { Name = "panel3", Text = "panel3", TabName = "tab2" }); //config.Panels.Add(new RevitPanel() { Name = "panel4", Text = "panel4", TabName = "tab2" }); var assemblyName = Assembly.GetExecutingAssembly().Location; var newAssembly = Path.Combine(Path.GetDirectoryName(assemblyName), "LRH.Tool.dll"); var newAssembly2 = Path.Combine(Path.GetDirectoryName(assemblyName), "FWindSoft.Revit.dll"); //config.Buttons.Add(new RevitButton() { PanelName = "panel1", Name = "button1", Text = "button1", AssemblyName = newAssembly, ClassName = "LRH.Tool.CreateBallFlagCommand", ButtonStyle = RevitButtonStyle.Push, IsStack = true }); //config.Buttons.Add(new RevitButton() { PanelName = "panel1", Name = "button2", Text = "button2", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Push, IsStack = true }); //config.Buttons.Add(new RevitButton() { PanelName = "panel1", Name = "button3", Text = "button3", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Push, IsStack = true }); //config.Buttons.Add(new RevitButton() { PanelName = "panel1", Name = "button4", Text = "button4", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Push }); //config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button1", Text = "button1", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Push }); //config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button2", Text = "button2", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Push }); //config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button3", Text = "button3", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Push }); //config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button4", Text = "button4", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Separator }); config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "cc", Text = "导出", AssemblyName = newAssembly, ClassName = "LRH.Tool.ExportDocumentToDwg3", ButtonStyle = RevitButtonStyle.Pulldown, IsStack = true }); config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button5", Text = "导出dwg", AssemblyName = newAssembly, ClassName = "LRH.Tool.ExportDocumentToDwg", ButtonStyle = RevitButtonStyle.Pulldown }); config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button6", Text = "button6", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Pulldown }); config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button51", Text = "button51", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand",GroupName="AA" ,ButtonStyle = RevitButtonStyle.Pulldown,IsStack=true}); config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button61", Text = "button61", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", GroupName = "AA", ButtonStyle = RevitButtonStyle.Pulldown }); config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button7", Text = "button7", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Split, IsStack = true }); config.Buttons.Add(new RevitButton() { PanelName = "panel2", Name = "button8", Text = "button8", AssemblyName = newAssembly2, ClassName = "RevitTest.ShowCommand", ButtonStyle = RevitButtonStyle.Split }); return config; } } }