Client/Desktop/KMBIM3.0/KMBIM3.0_소스/Cmd/TrimSpacing/ElementTrim.cs

119 lines
4.1 KiB
C#

using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Linq;
using Autodesk.Revit.UI.Selection;
using KDCS.Utils;
using Autodesk.Revit.DB.Structure;
using KMBIM.Revit.Tools.Cmd.SprinklerConnect;
using Autodesk.Revit.DB.Mechanical;
using KMBIM.Revit.Tools;
using Autodesk.Revit.DB.Plumbing;
namespace KMBIM
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class ElementTrim : IExternalCommand
{
UIApplication uiapp;
UIDocument uidoc;
Autodesk.Revit.DB.Document doc;
Autodesk.Revit.Creation.Application creApp;
Autodesk.Revit.Creation.Document creDoc;
Autodesk.Revit.UI.ExternalCommandData m_commandData;
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
m_commandData = commandData;
uiapp = commandData.Application;
uidoc = uiapp.ActiveUIDocument;
doc = uidoc.Document;
creApp = uiapp.Application.Create;
creDoc = doc.Create;
List<Element> m_ElemLst = new List<Element>();
try
{
if (!WorkMain.GetInstance().IsValid) return Autodesk.Revit.UI.Result.Succeeded;
while (true)
{
Reference pickRef = commandData.Application.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, new SelectionFilter(), "절단할 배관 또는 덕트 선택 : ");
XYZ Gpt = pickRef.GlobalPoint;
Element pickElem = doc.GetElement(pickRef);
using(Transaction trans = new Transaction(doc))
{
trans.Start("cutting");
XYZ sp = null, ep = null;
Line ElemLine = null;
if(pickElem is Pipe)
{
Util.GetStartEndPoint(pickElem as Pipe, ref sp, ref ep);
ElemLine = ((pickElem as Pipe).Location as LocationCurve).Curve as Line;
//선택점과 파이프 교차점 찾기.
IntersectionResult interRes = ElemLine.Project(Gpt);
XYZ DivPt = interRes.XYZPoint;
List<ElementId> ElemIdLst = new List<ElementId>();
ElemIdLst = Util.DivideElement(doc, pickElem as Pipe, DivPt);
}
else if(pickElem is Duct)
{
Util.GetStartEndPoint(pickElem as Duct, ref sp, ref ep);
ElemLine = ((pickElem as Duct).Location as LocationCurve).Curve as Line;
//선택점과 덕트 교차점 찾기.
IntersectionResult interRes = ElemLine.Project(Gpt);
XYZ DivPt = interRes.XYZPoint;
List<ElementId> ElemIdLst = new List<ElementId>();
ElemIdLst = Util.DivideElement(doc, pickElem as Duct, DivPt);
}
trans.Commit();
}
}//while end
}
catch (Exception e)
{
//MessageBox.Show("" + e);
}
return Result.Succeeded;
}
public class SelectionFilter : ISelectionFilter
{
public bool AllowElement(Element element)
{
if (element.Category == null) return false;
if (element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_PipeCurves
|| element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DuctCurves)
{
return true;
}
return false;
}
public bool AllowReference(Reference refer, XYZ point)
{
return false;
}
}
}
}