I am copying several elements from links or documents to the current project file opened with Dynamo with the nodes of rhythm or springs, but it takes so long because majority of elements contain other elements that Revit indicates they are duplicated and if I want to overwrite with OK button.
is possible to copy all without any question of Duplicate Types?
I suggest doing some research on python coding with the Revit API. It can seem like a big step but it’s incredibly powerful once you get comfortable with it.
The argument you have to supply is the object in green, IDuplicateTypeNamesHandler. If you click on it it will explain what it does and give you a link to all its members. You’d have to check the members to see how that value is set. You may even have to do this multiple times if the argument is another method that needs defining.
@c.poupin would you know what Argument the CopyHandler is expecting? I have not actually had to pass things like this in the past. @solamour@Michael_Kirschner2
import clr
import sys
import System
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
class CustomCopyHandler(IDuplicateTypeNamesHandler):
def OnDuplicateTypeNamesFound(self, args):
return DuplicateTypeAction.UseDestinationTypes
doc = DocumentManager.Instance.CurrentDBDocument
#Preparing input from dynamo to revit
linkInst = UnwrapElement(IN[0])
linkViews = UnwrapElement(IN[1])
newViews = UnwrapElement(IN[2])
LinkIds = []
NewIds = []
Items = []
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
opts = CopyPasteOptions()
opts.SetDuplicateTypeNamesHandler(CustomCopyHandler()) #Line 47 from Error
Items.append(ElementTransformUtils.CopyElements(linkView,List[ElementId](oldItems),newView,Transform.Identity,opts))
Yes, found this out rather quickly, and went back to IP2. I’ll stay there until there is another way to do it, but this is also why I’ll be eventually rolling this into an addin and remove the issue completely.
hello, I used this code to copy elements in order to modify them on the same page, but despite the code I do not find the same argument, only the ids, and I cannot modify them being refused as an element?
Thank you for any help you can give me
import clr
import sys
import System
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
current_doc = DocumentManager.Instance.CurrentDBDocument
class CustomCopyHandler(IDuplicateTypeNamesHandler):
# __namespace__ = "Autodesk.Revit.DB"
def OnDuplicateTypeNamesFound(self, args):
return DuplicateTypeAction.UseDestinationTypes
myElements = UnwrapElement(IN[0])
CopyElement = []
oldItems = []
copyOptions = CopyPasteOptions()
copyOptions.SetDuplicateTypeNamesHandler(CustomCopyHandler())
# start transaction
TransactionManager.Instance.ForceCloseTransaction()
TransactionManager.Instance.EnsureInTransaction(current_doc)
myElement = List[ElementId]([x.Id for x in myElements])
CopyElement = ElementTransformUtils.CopyElements(current_doc, myElement , current_doc , Transform.Identity , copyOptions)
#CopyElement.append(ElementTransformUtils.CopyElements(current_doc, myElement , current_doc , Transform.Identity , copyOptions))
TransactionManager.Instance.TransactionTaskDone()
OUT = CopyElement