CreateInstanceView Method (Document, ElementId)


Creates a new instance of this view (using default template)

Namespace: Autodesk.Revit.DB.Electrical
Assembly: RevitAPI (in RevitAPI.dll) Version: 22.0.0.0 (22.1.0.0)

Syntax

C#
public static PanelScheduleView CreateInstanceView(
	Document ADoc,
	ElementId panelId
)
Visual Basic
Public Shared Function CreateInstanceView ( _
	ADoc As Document, _
	panelId As ElementId _
) As PanelScheduleView
Visual C++
public:
static PanelScheduleView^ CreateInstanceView(
	Document^ ADoc, 
	ElementId^ panelId
)

Parameters

ADoc
Type: Autodesk.Revit.DB Document
The Document
panelId
Type: Autodesk.Revit.DB ElementId
Element id of the electrical panel element.

Return Value

The PanelScheduleView

Examples

Copy C#
// Create a new panel schedule and switch to that view
public void CreatePanelSchedule(UIDocument uiDocument)
{
    Document doc = uiDocument.Document;

    Reference selected = uiDocument.Selection.PickObject(ObjectType.Element, "Select an electrical panel");

    Element panel = doc.GetElement(selected);

    if (null != panel)
    {
        PanelScheduleView psv = null;

        using (Transaction trans = new Transaction(doc, "Create a new panel schedule"))
        {
            trans.Start();
            psv = PanelScheduleView.CreateInstanceView(doc, panel.Id);
            trans.Commit();
        }
        if (null != psv)
        {
            uiDocument.ActiveView = psv;    // make new view the active view
        }
        else
        {
            TaskDialog.Show("Revit", "Please select one electrical panel.");
        }
    }
}
Copy VB.NET
' Create a new panel schedule and switch to that view
Public Sub CreatePanelSchedule(uiDocument As UIDocument)
    Dim doc As Document = uiDocument.Document

    Dim selected As Reference = uiDocument.Selection.PickObject(ObjectType.Element, "Select an electrical panel")

    Dim panel As Element = doc.GetElement(selected)

    If panel IsNot Nothing Then
        Dim psv As PanelScheduleView = Nothing

        Using trans As New Transaction(doc, "Create a new panel schedule")
            trans.Start()
            psv = PanelScheduleView.CreateInstanceView(doc, panel.Id)
            trans.Commit()
        End Using
        If psv IsNot Nothing Then
                ' make new view the active view
            uiDocument.ActiveView = psv
        Else
            TaskDialog.Show("Revit", "Please select one electrical panel.")
        End If
    End If
End Sub

Exceptions

Exception Condition
Autodesk.Revit.Exceptions ArgumentNullException A non-optional argument was null

See Also

ArchiLabs Desktop

Put AI to work inside Revit.

Give Desktop your instructions and project files to build Revit families, update model elements, and create views and schedules. Works directly in Revit and AutoCAD.

Explore Desktop →