使用RevitAPI创建房间的时候有挺多地方不是特别明确的,对于我原本就很少,几乎没有在Revit中手动操作过房间的人来说就更难理解了。
RevitAPI Demo
Room InsertNewRoomInPlanCircuit(Autodesk.Revit.DB.Document document, Level level, Phase newConstructionPhase)
{
// create room using Phase
Room newScheduleRoom = document.Create.NewRoom(newConstructionPhase);
// set the Room Number and Name
string newRoomNumber = "101";
string newRoomName = "Class Room 1";
newScheduleRoom.Name = newRoomName;
newScheduleRoom.Number = newRoomNumber;
// Get a PlanCircuit
PlanCircuit planCircuit = null;
// first get the plan topology for given level
PlanTopology planTopology = document.get_PlanTopology(level);
// Iterate circuits in this plan topology
foreach (PlanCircuit circuit in planTopology.Circuits)
{
// get the first circuit we find
if (null != circuit)
{
planCircuit = circuit;
break;
}
}
Room newRoom2 = null;
if (null != planCircuit)
{
using (Transaction transaction = new Transaction(document, "Create Room"))
{
if (transaction.Start() == TransactionStatus.Started)
{
// The input room must exist only in the room schedule,
// meaning that it does not display in any plan view.
newRoom2 = document.Create.NewRoom(newScheduleRoom, planCircuit);
// a model room with the same name and number is created in the
// view where the PlanCircuit is located
if (null != newRoom2)
{
// Give the user some information
TaskDialog.Show("Revit", "Room placed in Plan Circuit successfully.");
}
transaction.Commit();
}
}
}
return newRoom2;
}
使用API创建房间的方法有三个:
public Room NewRoom(Phase phase)
public Room NewRoom(Level level,UV point)
public Room NewRoom(Room room,PlanCircuit circuit)
假如你已经有了一个闭合的轮廓需要在轮廓内创建房间的话,可以使用以下方法:
-
绘制房间分隔
//创建房间分隔
CurveArray slabCurveArray = new CurveArray();
foreach (var vmCeilingEdgeInfo in vm.CeilingEdgeInfos)
{
slabCurveArray.Append(vmCeilingEdgeInfo.Edge);
}var sketchPlane = SketchPlane.Create(ActiveDocument, Plane.CreateByNormalAndOrigin(-bottomFace.FaceNormal, bottomFace.Origin));
var viewPlan = FilterUtils.FilterByFunc(ActiveDocument, o => o.LookupParameter(“相关标高”)?.AsString() == level.Name).FirstOrDefault();
roomSepartions = ActiveDocument.Create.NewRoomBoundaryLines(sketchPlane, slabCurveArray, viewPlan);
ActiveDocument.Regenerate();
-
获取项目中同标高的所有轮廓并判断该轮廓是否已经生成房间
PlanCircuit planCircuit = null;
PlanTopology planTopology = ActiveDocument.get_PlanTopology(level);
foreach (PlanCircuit circuit in planTopology.Circuits)
{
if (null != circuit && !circuit.IsRoomLocated)
{
planCircuit = circuit;
break;
}
} -
创建房间(此方法中的阶段phase参数假如你不需要可以为null)
//创建房间
if (null != planCircuit)
{
var room = ActiveDocument.Create.NewRoom(null, planCircuit);
}
PS:
- 创建完房间后不可删除房间分隔线,否则房间则会变成没有轮廓范围而且没有面积的房间
- 创建房间的视图必须是平面视图,如果不是平时图则会报错(“尝试读取或写入受保护的内存。这通常指示其他内存已损坏”)。