using Autodesk.Revit.UI; using Autodesk.Revit.UI.Events; using HYJig; using System; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Windows.Forms; namespace ShowGridNumber { public class ShowGridApplication : IExternalApplication { public bool DrawGridNumber { get; set; } public Result OnStartup(UIControlledApplication application) { this.m_version = Convert.ToInt32(application.ControlledApplication.VersionNumber); ShowGridApplication.m_ThisApp = this; ShowGridApplication.m_gridNumberShowForm = new GridNumberForm(ShowGridApplication.m_ThisApp); application.ViewActivated += this.RuQoqPuaQ; application.Idling += this.method_0; this.method_2(); if (this.windowHandle_0 == null) { Process currentProcess = Process.GetCurrentProcess(); this.m_hRevitHandle = currentProcess.MainWindowHandle; this.windowHandle_0 = new WindowHandle(this.m_hRevitHandle); } return 0; } public Result OnShutdown(UIControlledApplication application) { application.ViewActivated -= this.RuQoqPuaQ; application.Idling -= this.method_0; ShowGridApplication.m_gridNumberShowForm.Close(); this.method_1(); return 0; } private void RuQoqPuaQ(object sender, ViewActivatedEventArgs e) { UIApplication uiapplication = sender as UIApplication; if (uiapplication == null) { return; } ShowGridApplication.m_gridNumberShowForm.UnLoad(); this.uidocument_0 = uiapplication.ActiveUIDocument; if (!this.DrawGridNumber) { ShowGridApplication.m_gridNumberShowForm.Hide(); } else if (!ShowGridApplication.m_gridNumberShowForm.Visible) { ShowGridApplication.m_gridNumberShowForm.Show(this.windowHandle_0); } if (this.m_version < 2019) { ShowGridApplication.m_gridNumberShowForm.RefreshDocAndView(this.uidocument_0); } else { ShowGridApplication.m_gridNumberShowForm.RefreshDocAndView2019(this.uidocument_0); } uiapplication.ActiveUIDocument.Document.Regenerate(); } private void method_0(object sender, IdlingEventArgs e) { if (this.uidocument_0 == null) { return; } ShowGridApplication.m_gridNumberShowForm.DrawGridNumText(true); } public void ShowHideGridNumber() { if (this.DrawGridNumber) { MessageBox.Show("全局轴号已关闭"); ShowGridApplication.m_gridNumberShowForm.Hide(); } else { ShowGridLevelNumOKForm showGridLevelNumOKForm = new ShowGridLevelNumOKForm(); if (this.m_bShowLink) { showGridLevelNumOKForm.chkShowLink.Checked = true; } else { showGridLevelNumOKForm.chkShowLink.Checked = false; } showGridLevelNumOKForm.ShowDialog(); ShowGridApplication.m_gridNumberShowForm.SetShowLinkDocGridNum(showGridLevelNumOKForm.chkShowLink.Checked); if (this.m_version < 2019) { ShowGridApplication.m_gridNumberShowForm.Show(this.windowHandle_0); } else { if (ShowGridApplication.m_gridNumberShowForm.Visible) { ShowGridApplication.m_gridNumberShowForm.Visible = false; } ShowGridApplication.m_gridNumberShowForm.Show(this.windowHandle_0); } ShowGridApplication.m_gridNumberShowForm.UnLoad(); if (this.m_version < 2019) { ShowGridApplication.m_gridNumberShowForm.RefreshDocAndView(this.uidocument_0); } else { ShowGridApplication.m_gridNumberShowForm.RefreshDocAndView2019(this.uidocument_0); } } this.DrawGridNumber = !this.DrawGridNumber; } private void method_1() { FileStream fileStream = new FileStream(Assembly.GetExecutingAssembly().Location + "\\ShowGridNumber.txt", FileMode.Create); StreamWriter streamWriter = new StreamWriter(fileStream); if (this.DrawGridNumber) { streamWriter.WriteLine("是"); } else { streamWriter.WriteLine("否"); } if (this.m_bShowLink) { streamWriter.WriteLine("是"); } else { streamWriter.WriteLine("否"); } streamWriter.Close(); fileStream.Close(); } private void method_2() { string text = Assembly.GetExecutingAssembly().Location + "\\ShowGridNumber.txt"; if (!File.Exists(text)) { this.DrawGridNumber = false; return; } FileStream fileStream = new FileStream(text, FileMode.Open); StreamReader streamReader = new StreamReader(fileStream); int num = 0; string text2 = string.Empty; while ((text2 = streamReader.ReadLine()) != null) { if (num == 0) { if (text2 == "是") { this.DrawGridNumber = true; } else { this.DrawGridNumber = false; } } if (num == 1) { if (text2 == "是") { this.m_bShowLink = true; } else { this.m_bShowLink = false; } } num++; } streamReader.Close(); fileStream.Close(); } public int m_version = 2016; public static ShowGridApplication m_ThisApp; public static GridNumberForm m_gridNumberShowForm; public IntPtr m_hRevitHandle = IntPtr.Zero; private UIDocument uidocument_0; private WindowHandle windowHandle_0; public bool m_bShowLink; } }