Client/Desktop/KMBIM3.0/KMBIM3.0_23.08.16_수정최종/Cmd/AvoidObstruction/KDCSRequestHandler.cs

119 lines
4.5 KiB
C#

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
{
/// <summary>
/// 대화상자에서의 요청을 실행한다.
/// </summary>
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();
/// <summary>
/// A public property to access the current request value
/// </summary>
public KDCSRequest Request
{
get { return m_request; }
}
/// <summary>
/// A method to identify this External Event Handler
/// </summary>
public String GetName()
{
return "KMBIM External Event Handler";
}
/// <summary>
/// The top method of the event handler.
/// </summary>
/// <remarks>
/// 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)
/// </remarks>
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<KDCSIntersectorElement> lstObstruction = new List<KDCSIntersectorElement>();
// 회피요소
List<KDCSIntersectorElement> lstAvoidance = new List<KDCSIntersectorElement>();
// 요소 가져오기
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
}