最近开发需要查找一个户型的最外圈墙。如下图所示:
经过一番研究,终于发现了一个完美方式,当然也是借助Revit本身功能。
思路如下:
在整个模型外圈用房间分隔线画一个包围框,然后创建房间,根据房间边界线找到墙。
private Room CreateOuterRoom(View view)
{
Document doc = view.Document;
List<Wall> wallList = doc.GetElements<Wall>();
Level level = view.GenLevel;
ElementId levelId = view.GenLevel.Id;
wallList = wallList.FindAll(p => p.LevelId == levelId);
if (wallList.Count > 0)
{
List<Wall> tempWallList = new List<Wall>();
double distance = 5;
List<Curve> curveList = wallList.Select(p => p.GetLocationCurve()).ToList();
List<XYZ> xyzList = curveList.Select(p => p.StartPoint()).ToList();
double xMax = xyzList.Max(p => p.X) + distance;
double xMin = xyzList.Min(p => p.X) - distance;
double yMax = xyzList.Max(p => p.Y) + distance;
double yMin = xyzList.Min(p => p.Y) - distance;
Transaction trans = new Transaction(wrapper.Doc, "CreateBoundary");
trans.Start();
try
{
tempWallList.ForEach(p => p.SetParameter(BuiltInParameter.WALL_ATTR_ROOM_BOUNDING, 0));
XYZ point1 = new XYZ(xMin, yMin, level.Elevation);
XYZ point2 = new XYZ(xMin, yMax, level.Elevation);
XYZ point3 = new XYZ(xMax, yMax, level.Elevation);
XYZ point4 = new XYZ(xMax, yMin, level.Elevation);
Line Line1 = Line.CreateBound(point1, point2);
Line line2 = Line.CreateBound(point2, point3);
Line line3 = Line.CreateBound(point3, point4);
Line line4 = Line.CreateBound(point4, point1);
CurveArray array = new CurveArray();
array.Append(Line1);
array.Append(line2);
array.Append(line3);
array.Append(line4);
//Plane plane = new Plane(XYZ.BasisZ, XYZ.Zero);
Plane plane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero);
SketchPlane sketchPlane = SketchPlane.Create(wrapper.Doc, plane);
ModelCurveArray modelCurveArray = doc.Create.NewRoomBoundaryLines(sketchPlane, array, view);
Level baseLevel = wallList[0].GetBaseLevel();
UV uv = new UV(xMin + 1, yMin + 1);
Room room = doc.Create.NewRoom(baseLevel, uv);
trans.Commit();
return room;
}
catch (Exception ex)
{
trans.RollBack();
}
}
return null;
}