Revit api 를 활용해 Model Line 선택 후 자동으로 바닥 그리는 방법
1 ) 선택한 개체를 필터링할 수 있는 인터페이스 구현
public class PlanarFacesSelectionFilter : ISelectionFilter
{
Document doc = null;
public PlanarFacesSelectionFilter(Document document)
{
doc = document;
}
public bool AllowElement(Element element)
{
return true;
}
public bool AllowReference(Reference refer, XYZ point)
{
if (doc.GetElement(refer).GetGeometryObjectFromReference(refer) is PlanarFace)
{
return true; // Only return true for planar faces. Non-planar faces will not be selectable
}
return false;
}
}
2 ) 바닥 생성하기
public void CreateFloor(Document document, UIDocument uidoc)
{
//1) 바닥을 생성하기 위한 세부사항들을 가져온다.
//1-1) 바닥을 생성하기 위한 floor type 을 가져온다.(floortype 종류 첫번째 것을 임의로 가져온다.)
FloorType floorType = new FilteredElementCollector(document).OfClass(typeof(FloorType)).FirstElement() as FloorType;
//1-2) 바닥을 생성하기 위한 level 을 가져온다. (level 종류 첫번째 것을 임의로 가져온다.)
Level level = new FilteredElementCollector(document).OfClass(typeof(Level)).FirstElement() as Level;
//1-3) Z 축은 기본 (0,0,1) 로 고정한다.
XYZ normal = XYZ.BasisZ;
// 2) 선택한 선분 가져오기
// 2-1) 프로젝트 상에서 내가 선택한 modelline 가져온다.
ISelectionFilter selFilter = new PlanarFacesSelectionFilter(document);
IList<Reference> references = uidoc.Selection.PickObjects(ObjectType.Element, selFilter, "Select multiple planar faces");
List<Element> elementlist = new List<Element>();
// 2-2) 선택한 line을 바탕으로 바닥을 그리기 위한 형변환
CurveArray profile = new CurveArray();
List<GeometryElement> geometryElements = new List<GeometryElement>();
foreach (Reference referen in references)
{
Element element = uidoc.Document.GetElement(referen);
elementlist.Add(element);
GeometryElement geometry = element.get_Geometry(new Options());
geometryElements.Add(geometry);
}
//2-3) 생성할 바닥 line 을 append 함수로 CurveArray에 담는다.
foreach (GeometryElement geometryele in geometryElements)
{
foreach (GeometryObject obj in geometryele)
{
if (obj is Curve)
{
profile.Append(obj as Curve);
}
}
}
// 3) transaction 열어 바닥 추가한다.
Transaction trans = new Transaction(document);
trans.Start("Create Floors");
document.Create.NewFloor(profile, floorType, level, true, normal);
trans.Commit();
}
반응형