DocumentNewRoom(Room, PlanCircuit) Method

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: 25.0.0.0 (25.0.0.0)
Syntax
public Room NewRoom(
	Room room,
	PlanCircuit circuit
)

Parameters

room  Room
The room which you want to locate in the circuit. Pass to create a new room.
circuit  PlanCircuit
The circuit in which you want to locate a room.

Return Value

Room
If successful the room is returned, otherwise .
Exceptions
ExceptionCondition
InvalidOperationExceptionIf the existing room is already placed.
ArgumentExceptionThrown if the room does not exist in the given document.
ArgumentExceptionThrown if the circuit does not exist in the given document.
InvalidOperationExceptionThrown if the level obtained from the circuit has no associated view .
Remarks
This method will regenerate the document even in manual regeneration mode.
Example
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;
}
See Also