Share

Document.NewRoom(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.3.0.0 (25.3.0.0)

Syntax

C#

public Room NewRoom(
	Room room,
	PlanCircuit circuit
)

Parameters

room  Room
The room which you want to locate in the circuit. Pass null 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 null.

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

C#

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;
}

VB

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

See Also

Reference

Was this information helpful?