* show를 사용하여 window를 띄울경우, window 에서 실행하는 작업이 Revit 에 영향을 주지 못하기 때문에 ExternalEventHandler로 이벤트를 사용해주어야한다.
window.Show()
Revit_Window window = new Revit_Window();
WindowInteropHelper wi = new WindowInteropHelper(window);
wi.Owner = Autodesk.Windows.ComponentManager.ApplicationWindow;
window.Show();
2) 창(window) 가 열리고 닫히기 전까지 Revit 의 다른 기능을 사용하지 못하고 싶은 경우
window.ShowDialog()
Revit_Window window = new Revit_Window();
WindowInteropHelper wi = new WindowInteropHelper(window);
wi.Owner = Autodesk.Windows.ComponentManager.ApplicationWindow;
window.ShowDialog();
Revit api 를 활용하여 line 선택시 교차점을 중심으로 line split 한 뒤 Duct 생성하기
[ 방법 ]
1)Line 가져오기
2)교차점을 중심으로 line 자르기
3)Line 잘라졌는지 확인하기 위해 Detail Line 그리기 ( 선택사항 )
4)파이프 생성
ISelectionFilter selectionFilter = new PlanarFacesSelectionFilter(document);
IList<Reference> references = uidoc.Selection.PickObjects(ObjectType.Element, selectionFilter, "Select Multiple planar faces");
List<Element> elementList = new List<Element>();
foreach (Reference reference in references)
{
Element element = uidoc.Document.GetElement(reference);
elementList.Add(element);
}
// 1-3) geometryElements 생성하기
List<Line> lines = new List<Line>();
foreach (Element element in elementList)
{
GeometryElement geometry = element.get_Geometry(new Options());
foreach (GeometryObject geometryObject in geometry)
{
Line line = geometryObject as Line;
lines.Add(line);
}
}
// 교차점이 있는지 확인하기
IntersectionResultArray results = null;
Line line1 = lines[0];
Line line2 = lines[1];
line1.Intersect(line2, out results);
IntersectionResult iResult = results.get_Item(0);
var IntersectPoint = iResult.XYZPoint;
if (IntersectPoint != null)
{
List<Line> splitLines = new List<Line>();
DetailLine detailLine1 = null;
DetailLine detailLine2 = null;
// 교차점 기준으로 라인 자르기
for (int i = 0; i < lines.Count; i++)
{
Curve curve = lines[i];
double paraIntersection = curve.Project(IntersectPoint).Parameter;
double startpam = curve.GetEndParameter(0);
double endpam = curve.GetEndParameter(1);
Curve curve1 = curve.Clone();
Curve curve2 = curve.Clone();
curve1.MakeBound(startpam, paraIntersection);
curve2.MakeBound(paraIntersection, endpam);
splitLines.Add(curve1 as Line);
splitLines.Add(curve2 as Line);
// 평면도에서 교차점 기준으로 잘라낸 선분이 보일 수 있도록 DETAILLINE 생성하기
detailLine1 = document.Create.NewDetailCurve(document.ActiveView, curve1) as DetailLine;
detailLine2 = document.Create.NewDetailCurve(document.ActiveView, curve2) as DetailLine;
}
lines.Clear();
lines = splitLines;
}
line split 전
line split 후
[ 주의할점 ]
1.2개의 line 에 교차점이 존재할 경우, 교차점을 기준으로 Curve Class 의 MakeBound를 이용하여 라인을 자른다. 이때, document 상에서는 4등분 된 line 이 보이지 않는다. 만약 document 상에서 split 된 line을 확인하고 싶다면 detailline 혹은 modelline을 생성하여 제대로 잘라졌는지 확인하면된다.
2.Datailline 을 그린 후 selection 할 시 3D 뷰에서는 선택되지 않는다. 따라서, level1과 같은 평면도에서 detail line을 선택해야한다.