这里是实现获取相交的一种方法,以选择相交柱子为示例。主要是把线构建成一个实体Solid然后再去计算相交。上代码~~
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
//收集所有的柱子
FilteredElementCollector columnFC = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_StructuralColumns);
Reference selRef;
try
{
selRef = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "选择目标线");
}
catch
{
return Result.Succeeded;
}
ModelCurve mc = doc.GetElement(selRef) as ModelCurve;
Line l = mc.GeometryCurve as Line;
//然后构件一个solid
XYZ firstPoint = l.GetEndPoint(0);
XYZ secPoint = l.GetEndPoint(1);
XYZ moveDir = l.Direction.CrossProduct(XYZ.BasisZ);
XYZ maxPoint = firstPoint.Add(moveDir * 10/304.8);
XYZ minPoint = secPoint.Add(moveDir * 10/304.8);
CurveLoop profile = new CurveLoop();
profile.Append(Line.CreateBound(firstPoint, maxPoint));
profile.Append(Line.CreateBound(maxPoint, minPoint));
profile.Append(Line.CreateBound(minPoint, secPoint));
profile.Append(Line.CreateBound(secPoint, firstPoint));
Solid s = GeometryCreationUtilities.CreateExtrusionGeometry(new List<CurveLoop>() { profile }, XYZ.BasisZ, 5000/304.8);
ElementIntersectsSolidFilter solidFilter = new ElementIntersectsSolidFilter(s, false);
List<FamilyInstance> columnList = columnFC.WherePasses(solidFilter).OfType<FamilyInstance>().ToList();
uidoc.Selection.SetElementIds(columnList.Select(x => x.Id).ToList());
这个是实现的效果,大家有其他的方法也可以一起交流和学习,今天就分享到这里啦