When using the ElementTransformUtils.CopyElements you may have the ‘Duplicate Types’ warning, as shown below.
In fact this method have one override option to pass a CopyPasteOptions parameter that enable us to control how Revit will react when this happens. We can return one of the following:
- UseDestinationTypes: Proceed with the paste operation and use the types with the same name in the destination document.
- Abort: Cancel the paste operation.
To implement this, first create a new class that implements the interface IDuplicateTypeNamesHandler. This class should have one method that returns the action. In the sample below, it will use destination types.
public class CustomCopyHandler : IDuplicateTypeNamesHandler{ public DuplicateTypeAction OnDuplicateTypeNamesFound( DuplicateTypeNamesHandlerArgs args) { return DuplicateTypeAction.UseDestinationTypes; }}
Then, at the CopyElements call, create a object of the type CopyPasteOptions and set the handler.
// create an instanceCopyPasteOptions copyOptions = new CopyPasteOptions();copyOptions.SetDuplicateTypeNamesHandler(new CustomCopyHandler()); // now the copyElementTransformUtils.CopyElements(doc1, ids, doc2, Transform.Identity, copyOptions);


Leave a Reply