qin
2024-09-28 e358beb08f5be49703009b64f058ecfbcfeefbd9
HStation.RevitDev/RevitDataExport/Entity/ExternalEvent.cs
@@ -3,6 +3,7 @@
using HStation.RevitDev.RevitDataExport.Common;
using HStation.RevitDev.RevitDataExport.Service;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
@@ -41,7 +42,7 @@
            }
            else
            {
                GlobalResource.InstancePlacing = false;
                GlobalResource.PlacingType = Model.ModelEnum.RevitType.RFT_Unknown;
                m_app.Idling -= App_Idling;
                m_isFirstTrigger = true;
            }
@@ -73,7 +74,7 @@
                trans.Start();
                try
                {
                    if (!doc.LoadFamily(RfaPath, new FamilyLoadOption(), out family))
                    if (!doc.LoadFamily(RfaPath, new ProjectLoadOption(), out family))
                    {
                        //说明文档中已经存在, 需要搜索整个文档
                        var elems = SearchService.SearchElements(doc, typeof(Family), Path.GetFileNameWithoutExtension(RfaPath));
@@ -136,7 +137,7 @@
            }
            else
            {
                GlobalResource.PipePlacing = false;
                GlobalResource.PlacingType = Model.ModelEnum.RevitType.RFT_Unknown;
                m_app.Idling -= App_Idling;
                m_isFirstTrigger = true;
            }
@@ -147,4 +148,53 @@
            return "Create Pipe";
        }
    }
    public class ExternalEvent_SelectElement : IExternalEventHandler
    {
        UIApplication m_uiapp = null;
        public static string m_id = null;
        public void Execute(UIApplication app)
        {
            m_uiapp = app;
            if (string.IsNullOrEmpty(m_id)) { return; }
            var id = new ElementId(int.Parse(m_id));
            m_uiapp.ActiveUIDocument.Selection.SetElementIds(new List<ElementId> { id });
            m_uiapp.ActiveUIDocument.ShowElements(id);
        }
        public string GetName()
        {
            return "Select Element";
        }
    }
    public class ExternalEvent_Execute : IExternalEventHandler
    {
        public ExternalEvent_Execute(string name)
        {
            Name = name;
        }
        public string Name { get; private set; }
        public Action<UIApplication> ExecuteAction { get; set; }
        public string GetName()
        {
            return Name;
        }
        public void Execute(UIApplication app)
        {
            if (ExecuteAction != null)
            {
                try
                {
                    ExecuteAction(app);
                }
                catch
                {
                }
            }
        }
    }
}