| Revit 2022 API |
| Document..::..NewRoom Method (Room, PlanCircuit) |
| Document Class Example See Also |
Creates a new room within the confines of a plan circuit, or places an unplaced room within the confines of the plan circuit.
Namespace: Autodesk.Revit.Creation
Assembly: RevitAPI (in RevitAPI.dll) Version: 22.0.0.0 (22.1.0.0)
Syntax
| C# |
|---|
public Room NewRoom( Room room, PlanCircuit circuit ) |
| Visual Basic |
|---|
Public Function NewRoom ( _ room As Room, _ circuit As PlanCircuit _ ) As Room |
| Visual C++ |
|---|
public: Room^ NewRoom( Room^ room, PlanCircuit^ circuit ) |
Parameters
- room
- Type: Autodesk.Revit.DB.Architecture..::..Room
The room which you want to locate in the circuit. Pass nullNothingnullptra null reference (Nothing in Visual Basic) to create a new room.
- circuit
- Type: Autodesk.Revit.DB..::..PlanCircuit
The circuit in which you want to locate a room.
Return Value
If successful the room is returned, otherwise nullNothingnullptra null reference (Nothing in Visual Basic).
Remarks
This method will regenerate the document even in manual regeneration mode.
Examples
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;
}Private Function InsertNewRoomInPlanCircuit(document As Autodesk.Revit.DB.Document, level As Level, newConstructionPhase As Phase) As Room ' create room using Phase Dim newScheduleRoom As Room = document.Create.NewRoom(newConstructionPhase) ' set the Room Number and Name Dim newRoomNumber As String = "101" Dim newRoomName As String = "Class Room 1" newScheduleRoom.Name = newRoomName newScheduleRoom.Number = newRoomNumber ' Get a PlanCircuit Dim planCircuit As PlanCircuit = Nothing ' first get the plan topology for given level Dim planTopology As PlanTopology = document.PlanTopology(level) ' Iterate circuits in this plan topology For Each circuit As PlanCircuit In planTopology.Circuits ' get the first circuit we find If circuit IsNot Nothing Then planCircuit = circuit Exit For End If Next Dim newRoom2 As Room = Nothing If planCircuit IsNot Nothing Then Using transaction As New Transaction(document, "Create Room") If transaction.Start() = TransactionStatus.Started Then ' 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 newRoom2 IsNot Nothing Then ' Give the user some information TaskDialog.Show("Revit", "Room placed in Plan Circuit successfully.") End If transaction.Commit() End If End Using End If Return newRoom2 End Function
Exceptions
| Exception | Condition |
|---|---|
| Autodesk.Revit.Exceptions..::..InvalidOperationException | If the existing room is already placed. |
| Autodesk.Revit.Exceptions..::..ArgumentException | Thrown if the room does not exist in the given document. |
| Autodesk.Revit.Exceptions..::..ArgumentException | Thrown if the circuit does not exist in the given document. |
| Autodesk.Revit.Exceptions..::..InvalidOperationException | Thrown if the level obtained from the circuit has no associated view . |