CopyPasteOption ().SetDuplicateTypeNamesHandler( IDuplicateTypeNamesHandler handler)

Hi All,

Does anyone know how to convert the following code to Python (from the sample SDK)?

CopyPasteOptions options = new CopyPasteOptions();
options.SetDuplicateTypeNamesHandler(new HideAndAcceptDuplicateTypeNamesHandler());


class HideAndAcceptDuplicateTypeNamesHandler : IDuplicateTypeNamesHandler
{

	public DuplicateTypeAction OnDuplicateTypeNamesFound(DuplicateTypeNamesHandlerArgs args)
        {
          return DuplicateTypeAction.UseDestinationTypes;
        }
}

image

image

import clr
clr.AddReference('RevitApi')
from Autodesk.Revit.DB import DuplicateTypeAction

dta = DuplicateTypeAction.UseDestinationTypes
OUT = dta

This should be sufficient though:

DuplicateTypeAction.UseDestinationTypes

Hi, could you please post your result?
I don´t get it to work. I want to replace families if the same name already exists. Currently it copies the object and adds a new family with the same name ending with a consecutive number.

options = CopyPasteOptions()
options.SetDuplicateTypeNamesHandler()

# I struggle with this area
#options.SetDuplicateTypeNamesHandler(new DuplicateTypeAction.UseDestinationTypes) 
#DuplicateTypeAction.UseDestinationTypes
#new IDuplicateTypeNamesHandler

TransactionManager.Instance.EnsureInTransaction(doc)
copy = ElementTransformUtils.CopyElements(linkDoc, eId, doc, tf1, options)
TransactionManager.Instance.TransactionTaskDone()

class CustomCopyHandler(IDuplicateTypeNamesHandler):
def OnDuplicateTypeNamesFound(self, args):
return DuplicateTypeAction.UseDestinationTypes

custom_handler = CustomCopyHandler()
copy_options = CopyPasteOptions()
copy_options.SetDuplicateTypeNamesHandler(custom_handler)

image
Snag_14f4940

I don’t work much with python, but when I see the error is this maybe the solution?
custom_handler = CustomCopyHandler().OnDuplicateTypeNamesFound()

Hi @jw.vanasselt, thanks for your response! I tried your script, it doesn’t work.
I wonder if it is a dynamo issue. I tried my original script in revit python shell, it’s working out fine. Very strange!


The problem relate to Cpython3 inside Dynamo, with RevitPythonShell still runing in Ironpython3, I’m not sure team fixed it in Revit 2024.2 yet.

I see interesting, thank you!