CopyElements Method (View, ICollection(ElementId), View, Transform, CopyPasteOptions)


Copies a set of elements from source view to destination view.

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

Syntax

C#
public static ICollection<ElementId> CopyElements(
	View sourceView,
	ICollection<ElementId> elementsToCopy,
	View destinationView,
	Transform additionalTransform,
	CopyPasteOptions options
)
Visual Basic
Public Shared Function CopyElements ( _
	sourceView As View, _
	elementsToCopy As ICollection(Of ElementId), _
	destinationView As View, _
	additionalTransform As Transform, _
	options As CopyPasteOptions _
) As ICollection(Of ElementId)
Visual C++
public:
static ICollection<ElementId^>^ CopyElements(
	View^ sourceView, 
	ICollection<ElementId^>^ elementsToCopy, 
	View^ destinationView, 
	Transform^ additionalTransform, 
	CopyPasteOptions^ options
)

Parameters

sourceView
Type: Autodesk.Revit.DB View
The view in the source document that contains the elements to copy.
elementsToCopy
Type: System.Collections.Generic ICollection ElementId
The set of elements to copy.
destinationView
Type: Autodesk.Revit.DB View
The view in the destination document that the elements will be pasted into.
additionalTransform
Type: Autodesk.Revit.DB Transform
The transform for the new elements, in addition to the transformation between the source and destination views. Can be a null reference ( Nothing in Visual Basic) if no transform is required. The transformation must be within the plane of the destination view.
options
Type: Autodesk.Revit.DB CopyPasteOptions
Optional settings. Can be a null reference ( Nothing in Visual Basic) if default settings should be used.

Return Value

The ids of the newly created copied elements.

Remarks

This method can be used for both view-specific and model elements.

Both source and destination views must be 2D graphics views capable of drawing details and view-specific elements (floor and ceiling plans, elevations, sections, drafting views.) Drafting views cannot be used as a destination for model elements.

The pasted elements are repositioned to ensure proper placement in the destination view (e.g. elevation is changed when copying from a level to a different level.) Additional transformation within the destination view can be performed by providing additionalTransform argument. This additional transformation must be within the plane of the destination view.

The destination view can be in the same document as the source view.

The destination view can be the same as the source view.

All view-specific elements in the set must be specific to the source view. Elements specific to views other than the source view or to multiple views cannot be copied.

This method performs rehosting of elements where applicable.

Examples

Copy C#
// The method copies view-specific DetailCurve.
public void CopyDetailCurve(Autodesk.Revit.DB.DetailCurve curve, Autodesk.Revit.DB.View destinationView)
{
   var ownerView = curve.Document.GetElement(curve.OwnerViewId) as Autodesk.Revit.DB.View;
   Transform transform = Transform.CreateTranslation(new XYZ(150, 150, 0));
   CopyPasteOptions options = new CopyPasteOptions();

   ElementTransformUtils.CopyElements(ownerView, new List<ElementId> { curve.Id }, destinationView, transform, options);
}

// The method copies sketch curves from the Floor Sketch to the Document to create independent ModelCurves
// that would replicate curves in the sketch.
public void CopySketchMembersToDocument(Autodesk.Revit.DB.Document document, Autodesk.Revit.DB.Floor floor, Autodesk.Revit.DB.View destinationView)
{
   var floorSketch = document.GetElement(floor.SketchId) as Sketch;
   // Select only curve elements from Sketch.
   var sketchCurves = floorSketch.GetAllElements().Where(id => document.GetElement(id) is ModelCurve).ToList();
   var transform = Transform.CreateTranslation(new XYZ(150, 150, 0));

   var copiedIds = ElementTransformUtils.CopyElements(
      destinationView, sketchCurves, destinationView, transform, new CopyPasteOptions());
}

Exceptions

Exception Condition
Autodesk.Revit.Exceptions ArgumentException The given element id set is empty. -or- The specified view cannot be used as a source or destination for copying elements between two views. -or- Some of the elements cannot be copied, because they belong to a different document. -or- Some of the elements cannot be copied, because they belong to a different view. -or- The elements cannot be copied into the destination view. Drafting views cannot contain model elements. -or- The transformation is not within the plane of the destination view. -or- The input set of elements contains Sketch members along with other elements and the Sketch Id of those members isn't in the set.
Autodesk.Revit.Exceptions ArgumentNullException A non-optional argument was null
Autodesk.Revit.Exceptions InvalidOperationException It is not allowed to copy Sketch members between non-parallel sketches. -or- The elements cannot be copied.
Autodesk.Revit.Exceptions OperationCanceledException User cancelled the operation.

See Also