From cd7d3ceff46090b1df76b96b788c2ffedb6f99f5 Mon Sep 17 00:00:00 2001
From: zhangyuekai <zhangyuekai@126.com>
Date: 星期四, 08 八月 2024 12:03:24 +0800
Subject: [PATCH] 添加缺失文件

---
 HStation.RevitDev/RevitDataExport/Entity/ExternalEvent.cs |  303 +++++++++++++++++++++++++-------------------------
 1 files changed, 150 insertions(+), 153 deletions(-)

diff --git a/HStation.RevitDev/RevitDataExport/Entity/ExternalEvent.cs b/HStation.RevitDev/RevitDataExport/Entity/ExternalEvent.cs
index 8666e7d..50ed6c8 100644
--- a/HStation.RevitDev/RevitDataExport/Entity/ExternalEvent.cs
+++ b/HStation.RevitDev/RevitDataExport/Entity/ExternalEvent.cs
@@ -1,153 +1,150 @@
-锘縰sing Autodesk.Revit.DB;
-using Autodesk.Revit.DB.Plumbing;
-using Autodesk.Revit.UI;
-using HStation.RevitDev.RevitDataExport.Service;
-using HStation.RevitDev.RevitDataExport.Utility;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Windows;
-
-namespace HStation.RevitDev.RevitDataExport.Entity
-{
-    public class ExternalEvent_CreateInstance : IExternalEventHandler
-    {
-        ExternalEvent m_createInstanceMonitor = null;
-        ExternalEvent_CloseInstanceMonitor m_closeInstanceMonitor = null;
-
-        public string RfaPath { get; set; } = null;
-
-        public void Execute(UIApplication app)
-        {
-            if (app == null || RfaPath == null || !File.Exists(RfaPath)) { return; }
-
-            UIDocument uiDoc = app.ActiveUIDocument;
-            Document doc = uiDoc.Document;
-            Family family = null;
-            FamilySymbol symbol = null;
-
-            LoadFamilyFile(doc, ref family, ref symbol);
-            if (family == null || symbol == null) { return; }
-
-            PlacementFamilyInstance(uiDoc, symbol);
-            m_closeInstanceMonitor = new ExternalEvent_CloseInstanceMonitor();
-            m_createInstanceMonitor = ExternalEvent.Create(m_closeInstanceMonitor);
-            m_createInstanceMonitor.Raise();
-        }
-
-        private static void PlacementFamilyInstance(UIDocument uiDoc, FamilySymbol symbol)
-        {
-            if (uiDoc.CanPlaceElementType(symbol))
-            {
-                try
-                {
-                    uiDoc.PromptForFamilyInstancePlacement(symbol, new PromptForFamilyInstancePlacementOptions());
-                }
-                catch (Autodesk.Revit.Exceptions.OperationCanceledException e)
-                {
-                    return;
-                }
-            }
-            else
-            {
-                MessageBox.Show("鏃犳硶鏀剧疆姝ょ被鏃�!");
-            }
-        }
-
-        private void LoadFamilyFile(Document doc, ref Family family, ref FamilySymbol symbol)
-        {
-            using (Transaction trans = new Transaction(doc, "鍒涘缓鏃忓疄渚�"))
-            {
-                trans.Start();
-                try
-                {
-                    if (!doc.LoadFamily(RfaPath, new FamilyLoadOption(), out family))
-                    {
-                        //璇存槑鏂囨。涓凡缁忓瓨鍦�, 闇�瑕佹悳绱㈡暣涓枃妗�
-                        var elems = SearchService.SearchElements(doc, typeof(Family), Path.GetFileNameWithoutExtension(RfaPath));
-                        if (elems != null && elems.Count > 0)
-                        {
-                            family = elems[0] as Family;
-                        }
-                    }
-                    if (family == null)
-                    {
-                        trans.Commit();
-                        return;
-                    }
-
-                    var symbolId = family.GetFamilySymbolIds().FirstOrDefault();
-                    symbol = doc.GetElement(symbolId) as FamilySymbol;
-                    if (symbol == null)
-                    {
-                        trans.Commit();
-                        return;
-                    }
-                    symbol.Activate();
-                }
-                catch (Exception ex)
-                {
-
-                }
-                trans.Commit();
-            }
-        }
-
-        public string GetName()
-        {
-            return "Create Family Instance";
-        }
-    }
-
-    public class ExternalEvent_CreatePipe : IExternalEventHandler
-    {
-        UIApplication m_app = null;
-
-        public void Execute(UIApplication app)
-        {
-            m_app = app;
-            PipeUpdater updater = new PipeUpdater(Common.GlobalResource.UpdaterGuid);
-            updater.Register();
-
-            RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.Pipe);
-            if (m_app.CanPostCommand(id))
-            {
-                m_app.PostCommand(id);
-            }
-        }
-
-        public string GetName()
-        {
-            return "Create Pipe";
-        }
-    }
-
-    public class ExternalEvent_ClosePipeMonitor : IExternalEventHandler
-    {
-        public void Execute(UIApplication app)
-        {
-            Common.GlobalResource.PipePlacing = false;
-            PipeUpdater updater = new PipeUpdater(Common.GlobalResource.UpdaterGuid);
-            updater.RemoveRegister();
-        }
-
-        public string GetName()
-        {
-            return "Create Pipe";
-        }
-    }
-
-    public class ExternalEvent_CloseInstanceMonitor : IExternalEventHandler
-    {
-        public void Execute(UIApplication app)
-        {
-            Common.GlobalResource.InstancePlacing = false;
-        }
-
-        public string GetName()
-        {
-            return "CloseInstanceMonitor";
-        }
-    }
-}
+锘縰sing Autodesk.Revit.DB;
+using Autodesk.Revit.UI;
+using HStation.RevitDev.RevitDataExport.Common;
+using HStation.RevitDev.RevitDataExport.Service;
+using System;
+using System.IO;
+using System.Linq;
+using System.Windows;
+
+namespace HStation.RevitDev.RevitDataExport.Entity
+{
+    public class ExternalEvent_CreateInstance : IExternalEventHandler
+    {
+        public string RfaPath { get; set; } = null;
+
+        private bool m_isFirstTrigger = true;
+
+        private UIApplication m_app = null;
+
+        public void Execute(UIApplication app)
+        {
+            if (app == null || RfaPath == null || !File.Exists(RfaPath)) { return; }
+            m_app = app;
+            m_app.Idling += App_Idling;
+            UIDocument uiDoc = app.ActiveUIDocument;
+            Document doc = uiDoc.Document;
+            Family family = null;
+            FamilySymbol symbol = null;
+
+            LoadFamilyFile(doc, ref family, ref symbol);
+            if (family == null || symbol == null) { return; }
+
+            PlacementFamilyInstance(uiDoc, symbol);
+        }
+
+        private void App_Idling(object sender, Autodesk.Revit.UI.Events.IdlingEventArgs e)
+        {
+            if (m_isFirstTrigger)
+            {
+                m_isFirstTrigger = false;
+            }
+            else
+            {
+                GlobalResource.InstancePlacing = false;
+                m_app.Idling -= App_Idling;
+                m_isFirstTrigger = true;
+            }
+        }
+
+        private static void PlacementFamilyInstance(UIDocument uiDoc, FamilySymbol symbol)
+        {
+            if (uiDoc.CanPlaceElementType(symbol))
+            {
+                try
+                {
+                    uiDoc.PromptForFamilyInstancePlacement(symbol, new PromptForFamilyInstancePlacementOptions());
+                }
+                catch (Autodesk.Revit.Exceptions.OperationCanceledException e)
+                {
+                    return;
+                }
+            }
+            else
+            {
+                MessageBox.Show("鏃犳硶鏀剧疆姝ょ被鏃�!");
+            }
+        }
+
+        private void LoadFamilyFile(Document doc, ref Family family, ref FamilySymbol symbol)
+        {
+            using (Transaction trans = new Transaction(doc, "鍒涘缓鏃忓疄渚�"))
+            {
+                trans.Start();
+                try
+                {
+                    if (!doc.LoadFamily(RfaPath, new FamilyLoadOption(), out family))
+                    {
+                        //璇存槑鏂囨。涓凡缁忓瓨鍦�, 闇�瑕佹悳绱㈡暣涓枃妗�
+                        var elems = SearchService.SearchElements(doc, typeof(Family), Path.GetFileNameWithoutExtension(RfaPath));
+                        if (elems != null && elems.Count > 0)
+                        {
+                            family = elems[0] as Family;
+                        }
+                    }
+                    if (family == null)
+                    {
+                        trans.Commit();
+                        return;
+                    }
+
+                    var symbolId = family.GetFamilySymbolIds().FirstOrDefault();
+                    symbol = doc.GetElement(symbolId) as FamilySymbol;
+                    if (symbol == null)
+                    {
+                        trans.Commit();
+                        return;
+                    }
+                    symbol.Activate();
+                }
+                catch (Exception ex)
+                {
+
+                }
+                trans.Commit();
+            }
+        }
+
+        public string GetName()
+        {
+            return "Create Family Instance";
+        }
+    }
+
+    public class ExternalEvent_CreatePipe : IExternalEventHandler
+    {
+        UIApplication m_app = null;
+        bool m_isFirstTrigger = true;
+
+        public void Execute(UIApplication app)
+        {
+            m_app = app;
+            app.Idling += App_Idling;
+
+            RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.Pipe);
+            if (m_app.CanPostCommand(id))
+            {
+                m_app.PostCommand(id);
+            }
+        }
+
+        private void App_Idling(object sender, Autodesk.Revit.UI.Events.IdlingEventArgs e)
+        {
+            if (m_isFirstTrigger)
+            {
+                m_isFirstTrigger = false;
+            }
+            else
+            {
+                GlobalResource.PipePlacing = false;
+                m_app.Idling -= App_Idling;
+                m_isFirstTrigger = true;
+            }
+        }
+
+        public string GetName()
+        {
+            return "Create Pipe";
+        }
+    }
+}

--
Gitblit v1.9.3