Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 24.0.0.0 (24.0.0.0)
Since: 2014
Syntax
C# |
---|
|
Visual Basic |
---|
|
Visual C++ |
---|
|
Parameters
- sourceView
- Type: Autodesk.Revit.DBView
The view in the source document that contains the elements to copy.
- elementsToCopy
- Type: System.Collections.GenericICollectionElementId
The set of elements to copy.
- destinationView
- Type: Autodesk.Revit.DBView
The view in the destination document that the elements will be pasted into.
- additionalTransform
- Type: Autodesk.Revit.DBTransform
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.DBCopyPasteOptions
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

// 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.ExceptionsArgumentException | 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.ExceptionsArgumentNullException | A non-optional argument was null |
Autodesk.Revit.ExceptionsInvalidOperationException | It is not allowed to copy Sketch members between non-parallel sketches. -or- The elements cannot be copied. |
Autodesk.Revit.ExceptionsOperationCanceledException | User cancelled the operation. |