Duplicate Method


Duplicates this view.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 24.0.0.0 (24.0.0.0)
Since:  2013

Syntax

C#
public ElementId Duplicate(
	ViewDuplicateOption duplicateOption
)
Visual Basic
Public Function Duplicate ( _
	duplicateOption As ViewDuplicateOption _
) As ElementId
Visual C++
public:
ElementId^ Duplicate(
	ViewDuplicateOption duplicateOption
)

Parameters

duplicateOption
Type: Autodesk.Revit.DBViewDuplicateOption
The option to use when duplicating the view.

Return Value

The id of the newly created view.

Examples

CopyC#
public View CreateDependentCopy(View view)
{
    View dependentView = null;
    ElementId newViewId = ElementId.InvalidElementId;
    if (view.CanViewBeDuplicated(ViewDuplicateOption.AsDependent))
    {
        newViewId = view.Duplicate(ViewDuplicateOption.AsDependent);
        dependentView = view.Document.GetElement(newViewId) as View;
        if (null != dependentView)
        {
            if (dependentView.GetPrimaryViewId() == view.Id)
            {
                TaskDialog.Show("Dependent View", "Dependent view created successfully!");
            }
        }
    }

    return dependentView;
}
CopyVB.NET
Public Function CreateDependentCopy(view As View) As View
    Dim dependentView As View = Nothing
    Dim newViewId As ElementId = ElementId.InvalidElementId
    If view.CanViewBeDuplicated(ViewDuplicateOption.AsDependent) Then
        newViewId = view.Duplicate(ViewDuplicateOption.AsDependent)
        dependentView = TryCast(view.Document.GetElement(newViewId), View)
        If dependentView IsNot Nothing Then
            If dependentView.GetPrimaryViewId() = view.Id Then
                TaskDialog.Show("Dependent View", "Dependent view created successfully!")
            End If
        End If
    End If

    Return dependentView
End Function

Exceptions

ExceptionCondition
Autodesk.Revit.ExceptionsArgumentOutOfRangeException A value passed for an enumeration argument is not a member of that enumeration
Autodesk.Revit.ExceptionsInvalidOperationException View cannot be duplicated

See Also

ArchiLabs

Stop fighting Revit automation.

Build repeatable BIM design and documentation workflows with scripts, data, and AI in one place, without wrestling brittle one-off automations.

Try ArchiLabs →