项目中会遇到存在多个独立的楼板组合成一个大楼板的情况,去下图:
今天分享的知识是把楼板给拆分开,变成单个独立的楼板,如下图:
上代码,Just Do It~~~
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Reference selRef = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "选择楼板");
Floor selFloor = doc.GetElement(selRef) as Floor;
//楼板的类型
FloorType ft = selFloor.FloorType;
Level fl = doc.GetElement(selFloor.LevelId) as Level;
GeometryElement geo = selFloor.get_Geometry(new Options());
//用来记录单个轮廓
List<CurveLoop> clList = new List<CurveLoop>();
foreach (GeometryObject geoObj in geo)
{
Solid floorSolid = geoObj as Solid;
if (floorSolid == null) continue;
//得到每一块楼板自己的solid
List<Solid> solidList = SolidUtils.SplitVolumes(floorSolid).ToList();
foreach (var s in solidList)
{
//再取每一块楼板的底面
foreach (var f in s.Faces)
{
//这里只以平面为例
PlanarFace pf = f as PlanarFace;
if (pf == null) continue;
if (Math.Abs(pf.FaceNormal.X) < 0.01 && Math.Abs(pf.FaceNormal.Y) < 0.01 && pf.FaceNormal.Z > 0)
{
List<CurveLoop> faceCLList = pf.GetEdgesAsCurveLoops().ToList();
clList.AddRange(faceCLList);
}
}
}
}
Transaction trans = new Transaction(doc, "创建新板");
trans.Start();
//先把楼板删除了
doc.Delete(selFloor.Id);
foreach (var cl in clList)
{
CurveArray ca = new CurveArray();
cl.OfType<Curve>().ToList().ForEach(x => ca.Append(x));
doc.Create.NewFloor(ca, ft, fl, false);
}
trans.Commit();
return Result.Succeeded;
主要使用的API:
1、把楼板的solid拆分成多个solid:
2、得到平面的外围线轮廓
最后就是生成楼板就可以拉,希望可以帮到你,今天就分享到这里,如果能点赞将是对我最大的鼓励。