Copy ElementType from Active Document to Background Document

I’m trying to write a script that can copy a selected ElementType to a container project. I’m trying the Orchid node Document.CopyElement, and it works well to copy from background document to the Active document, but when i try the other way i get the warning ‘Attempt to modify the model outside of transaction’. I’ve tried placing transaction start/ends in a couple of spots, but i don’t get a successful result.

Is there a way to do this natively in dynamo? I tried Document.TransferByElementType (again, from active to background) in the Orchid package, but i get the warning ‘the referenced object is not valid, possibly because it has been deleted from the database, or its creation was undone’

i’m not currently able to upload the graph image.

You cannot copy anything to a linked document unless you actually open it up in the background.

i don’t mean a linked document. i’d prefer to have this work without linking documents at all. I’m trying to open a doc in the background and copy the selection to it.

Some updates on this:

was able to make this work using python (code at end). It’s unclear why the Orchid node ‘Document.CopyElement’ is unable to use the non-current document as the target, but i get the warning ‘Attempt to modify the model outside of transaction’

The script is only able to run if the target document is opened by the user before running the script. Orchid package seems to refer to a ‘background open’ but that doesn’t seem to be a designation in the API, so i don’t really know the right way to call it. I think the UX is better for what i’m trying to do if i can do all the operations with the target/container file outside of the user’s view, but this works for now.

import clr

# all references
clr.AddReference('RevitAPI')
clr.AddReference('System')
clr.AddReference('RevitServices')

# all imports
from System.Collections.Generic import List
import Autodesk.Revit.DB
from RevitServices.Transactions import TransactionManager

# inputs in python node
sDoc = IN[0]
dDoc = IN[1]
elements = IN[2]

# gets id from groups
ids = []
for e in elements:
	ids.append(e.InternalElement.Id)

# creates a icollection of elementid
idCol = List[Autodesk.Revit.DB.ElementId](ids)

# Start transaction between documents
for tDoc in dDoc:
	TransactionManager.Instance.EnsureInTransaction(tDoc)
	
	# copys the groups from sDoc to dDoc
	new = Autodesk.Revit.DB.ElementTransformUtils.CopyElements(sDoc,idCol,tDoc,transform = None,options = None)
	
	# ends transaction
	TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.
# the unique group id of the copyed group
OUT = new

Ok, i think i found the real culprit here.

I needed to add a Transaction.End on the background document so that it’s available for dynamo (not sure of the right terminology for this)