using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Electrical; using Autodesk.Revit.DB.Mechanical; using Autodesk.Revit.DB.Plumbing; using Autodesk.Revit.UI; using KMBIM.Revit.Tools; using KMBIM.Revit.Tools.Utils; namespace KMBIM { /// /// 대화상자에서의 요청을 실행한다. /// public class KDCSRequestHandler : IExternalEventHandler { // A trivial delegate, but handy private delegate void DoorOperation(FamilyInstance e); // The value of the latest request made by the modeless form private KDCSRequest m_request = new KDCSRequest(); /// /// A public property to access the current request value /// public KDCSRequest Request { get { return m_request; } } /// /// A method to identify this External Event Handler /// public String GetName() { return "KMBIM External Event Handler"; } /// /// The top method of the event handler. /// /// /// This is called by Revit after the corresponding /// external event was raised (by the modeless form) /// and Revit reached the time at which it could call /// the event's handler (i.e. this object) /// public void Execute(UIApplication uiapp) { UIDocument uidoc = uiapp.ActiveUIDocument; try { Resolver resolver = Request.Take(); if (resolver != null) { if (uidoc != null) { using (Transaction trans = new Transaction(uidoc.Document, "Avoid Obstruction")) { // 충돌요소 List lstObstruction = new List(); // 회피요소 List lstAvoidance = new List(); // 요소 가져오기 resolver.GetElement(ref lstObstruction, ref lstAvoidance); // 회피 요소를 하나씩 벤딩한다. foreach (KDCSIntersectorElement crvelm in lstAvoidance) { try{ trans.Start(); if (crvelm.ElementType == typeof(Duct)) { resolver.Bend(crvelm.Element as Duct, crvelm.HitPoint, ref lstObstruction); } else if (crvelm.ElementType == typeof(Pipe)) { resolver.Bend(crvelm.Element as Pipe, crvelm.HitPoint, ref lstObstruction); } else if (crvelm.ElementType == typeof(CableTray)) { resolver.Bend(crvelm.Element as CableTray, crvelm.HitPoint, ref lstObstruction); } else if (crvelm.ElementType == typeof(Conduit)) { resolver.Bend(crvelm.Element as Conduit, crvelm.HitPoint, ref lstObstruction); } trans.Commit(); } catch (Exception ex) { trans.RollBack(); System.Windows.Forms.MessageBox.Show(ex.Message); } }//for-each } } } } finally { App.thisApp.WakeFormAvoidObstruction(); } return; } }//end-class }