Copy Elements from Linked Revit File Failure

I am trying to copy Floors from Linked Revit File.

I get a warning as below:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 28, in
Exception: Copying one or more elements failed.

The overall operation fails because of a few elements. Please tell me how I could ignore these exceptions as the operation runs as a set of elements to be copied.

Python Script as below:

import clr,System
clr.AddReference(“RevitServices”)
clr.AddReference(“RevitAPI”)

from Autodesk.Revit.DB import *
from System.Collections.Generic import List
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

current document

doc = DocumentManager.Instance.CurrentDBDocument

input link document

linkdoc = UnwrapElement(IN[0])

#collect levels from the link document
collector = FilteredElementCollector(linkdoc).OfClass(Floor).ToElements()

convert python list

collector = list(collector)

dot-net elementId list

ids = List[ElementId]([i.Id for i in collector])

transaction start

copied_elements =
TransactionManager.Instance.EnsureInTransaction(doc)
copied_elements = ElementTransformUtils.CopyElements(linkdoc,ids,doc,Transform.Identity,CopyPasteOptions())

transaction done

TransactionManager.Instance.TransactionTaskDone()

output

OUT = copied_elements

Are you trying to copy floor instances, or floor types?

Also, just use the ToElementIds() method on the collector rather than ToElements() only to get the IDs.

I am trying to copy floor instances

Use .OfCategory(BuiltInCategory.OST_Floors). WhereElementIsNotElementType().ToElementIds() in lieu of OfClass() in the FEC.

1 Like

Its not working it still throws the same error, the problem I am facing lies on this line:

copied_elements = ElementTransformUtils.CopyElements(linkdoc,collector,doc,Transform.Identity,CopyPasteOptions())

Certain Elements are not being copied and hence the whole command fails, is there a method I could use to filter out the elements that cannot be copied and the copy/paste happens for the elements that could be copied.

Try using None for the Transform.

copied_elements = ElementTransformUtils.CopyElements(linkdoc,collector,doc,None,CopyPasteOptions())

Still throw the same error.

I just tested this out, and this worked for me.

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

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

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

#Preparing input from dynamo to revit
LinkDoc = UnwrapElement(IN[0])

#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

floors = FilteredElementCollector(LinkDoc[0]).OfCategory(BuiltInCategory.OST_Floors).WhereElementIsNotElementType().ToElementIds()

copied = ElementTransformUtils.CopyElements(LinkDoc[0],floors,doc,None,CopyPasteOptions())

TransactionManager.Instance.TransactionTaskDone()

OUT = floors,copied

I agree with you, the instances that you are trying to copy does not have any errors.
As you can read the Exception as below that I am facing:
"Exception: Copying one or more elements failed."
It does copy the elements, but it fails as a set as in some cases it may have errors.
Is there or might be way to weed out these failed elements and let the copy/paste function happen.

You could wrap it into a Try / Except block and iterate the collection one floor at a time.

for floor in floors:
	try:
		copied.append(ElementTransformUtils.CopyElements(LinkDoc[0],List[ElementId]([floor.Id]),doc,None,CopyPasteOptions()))
	except:
		copied.append("Bad Floor: " + floor.Id.ToString())
        continue

Thank you, it does work till it arrives at the bad element, and fails to continue.

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 29, in
AttributeError: ‘List[ElementId]’ object has no attribute 'append

After researching I found the script works perfectly. The issue was in Revit, I was getting the following error:

Selection cannot be copied.
Can’t Copy to Clipboard because of relationships between Elements

1 Like

Hey Roshan!

I am having the same problem as you had. How did you overcome this? My case is a little different as I try to copy Views from linked file to host file.

Hi @jazlik and welcome :grinning:
please start a new topic to explain your problem,
consider adding to your message:

  • a screenshot of your dynamo graph
  • the python code
1 Like