ElementTransformUtils.CopyElement

Hi Im trying to copy a list of elements from a link to mi current document using
ElementTransformUtils.CopyElement, the one with 5 arguments.
CopyElements Method (Document, ICollection(ElementId), Document, Transform, CopyPasteOptions)
However, i get the “CopyElement() takes exactly 3 arguments (5 given)” error.

Any help?

Thanks in advance!

import clr
import System
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager


import Autodesk

doc = DocumentManager.Instance.CurrentDBDocument

dataEnteringNode = IN




elements = UnwrapElement(IN[0])
linkdoc = IN[1]
linkdoc = linkdoc[0]
copiedelem = []
for i in elements:

copy = ElementTransformUtils.CopyElement(linkdoc,i.Id,doc,None, CopyPasteOptions())
copiedelem.append(copy)

OUT = copiedelem

You need to input a transform and ensure all your inputs are unwrapped and valid - the python interpreter is basically telling you it cant establish which overload you’re calling as it cant match your inputs to any method signature.

1 Like

Thansk for the quick reply Thomas, and for the Bimorph nodes. Have been using them for a long time and finally stepping up to developing my own ones.

The issue here is that I want to copy elements “aligned to the same place” but I’'m struggling to find in the API how to input those settings. I though that the upper example defined them as defaults. Some light would be aprecciated.

https://www.revitapidocs.com/2016/b22df8f6-3fa3-e177-ffa5-ba6c639fb3dc.htm

And for the record, this is a middle step towards getting all the views and sheets in which a linked element appears.
The main problem is that the API wont allow to do that with linked elements, so there is a workaround in which you recreate a bounding box of the element and find it on views. Which is a problem because view filters wont work for them. So I’m going to temporally copy those elements to the current document, find the view/sheets, and then delete the copied elements.

If a method is expecting a different amount of arguments than what you’re providing (and you’re providing a valid number of arguments) it usually means one or more of your arguments is not in the right format/class.

Yes thanks Nick, the arguments that I’m passing with another or incorrect format are the two last ones, Transform And CopyOptions.

That’s where I’m struggling to find what I have to input.

I mean, in transform, do I have to get the XYZ of the link elements to be copied?

In copyOptions, do I have to input some kind of Id that referes to “CopyAligned” command of revit?

Look at the methods for both of those classes to see what’s available and what you need. You would get the proper transform so that your elements get pasted in the same relative place. There is no option for “CopyAligned”.

Yes that’'s why I created this thread… I have been investigating for a while and can’t find enough info to find the correct last two slots.

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

As I said, you will need to determine the difference in coordinate systems between the documents and apply that to the Transform. That is how you ensure that the elements are pasted aligned. You can likely ignore the CopyPasteOptions in this case.
Transform Members: link
CopyPasteOptions Members: link

Hello
you are missing an “s”


and with CopyElements() method you need a ICollection(ElementId), no a single ElementId try with this example

import clr
import sys
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

#Get Important vars
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument
app = uiapp.Application

from System.Collections.Generic import List

"""
some lines of code
and Start transaction 
"""

copyOptions = CopyPasteOptions()
elementIds = [x.Id for x  in elements]
copyElems = ElementTransformUtils.CopyElements(soucDoc, List[ElementId](elementIds), currentDoc, None, copyOptions)
"""
rest of code
and End transaction 
"""
3 Likes

Thank you very much to everyone, Im working on it and will post updates soon

Hi everyone, sorry for the late replies.

I’ve been working on it and solved the issue passing null and default values to those last two parameters.
But now I have a new issue.
For the record, I’ve moved to C# and visual studio.

The problem is that the elements copy themselves with a small offset.

I’ve tried correcting it with the proceeding method, but the issue continues (with a smaller offset, but still there).

Anyone with a solution?

Thanks!

            List<ElementId> newElements = (List<ElementId>)ElementTransformUtils.CopyElements(linkedDocument, new List<ElementId> { elemId }, doc, null, new CopyPasteOptions());

        Element linkedElem = linkedDocument.GetElement(elemId);
        Element copiedElem = doc.GetElement(newElements.First());
        
        /// CORRECT THE POSITION OFFSET
        try {
            if (offsetPoint == null)
            {
                ProjectPosition linkedPP = linkedDocument.ActiveProjectLocation.GetProjectPosition((linkedElem.Location as LocationPoint).Point);
                ProjectPosition thisPP = doc.ActiveProjectLocation.GetProjectPosition((copiedElem.Location as LocationPoint).Point);
                offsetPoint = new XYZ(linkedPP.EastWest - thisPP.EastWest,
                                      linkedPP.NorthSouth - thisPP.NorthSouth,
                                      linkedPP.Elevation - thisPP.Elevation);
                ElementTransformUtils.MoveElement(doc, newElements.First(), offsetPoint);
            }
            else
            {
                ElementTransformUtils.MoveElement(doc, newElements.First(), offsetPoint);
            }
        }
        catch (Exception) { }