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 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.
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
Greetings, could you please let me know -how you managed to make it work!
i have similar requirement where, i have certain 3d views with specific elements in active document/model & i have to save them into separate files . i have already created the required rvt files-these files are not linked to any model or so . now from active document i have to copy paste certain elements to each of them .i tried you method of putting in transaction start & end but i get the following results. for some reason the elements seems to show empty or auto deleted . do not understand why. did try python as well that you had posed but i am not good at python so not sure as i have listed elements ( document at L1 vs elements at L2).