How does IDuplicateTypeNamesHandler work ?

How does IDuplicateTypeNamesHandler work ?

Anonymous
Not applicable
1,723 Views
7 Replies
Message 1 of 8

How does IDuplicateTypeNamesHandler work ?

Anonymous
Not applicable

Hello,

 

I'm using the code from this site :

http://adndevblog.typepad.com/aec/2013/05/copy-family-between-documents-via-api.html

 

I want to copy wall types from one document to another. 

 

ElementTransformUtils.CopyElements () has a option called CopyPasteOptions .

 

When I use new CopyPasteOptions() Revit will give a message saying he will NOT overwrite the wall types but make a copy.

 

I don't want to make a copy, I realy want to overwrite the wall types.

 

The CopyPasteOptions has an option SetDuplicateTypeNamesHandler(IDuplicateTypeNamesHandler handler)

 

This is where I get stuck, how can I use this IDuplicateTypeNamesHandler ?? (so that Revit will overwrite the wall types and not insert the new ones as a copy) ?

 

 

1,724 Views
7 Replies
Replies (7)
Message 2 of 8

arnostlobel
Alumni
Alumni

Hello Remy van den Bor:

 

The callback DuplicateTypeNamesHandler class does not allow one to replace types in the destination document. The handler is called when there are types with names identical to different types from the source document (the one the types are copied from.) The programmer has only two options to handle the situation: Either to cancel the copying action all together, or to proceed with copying but only with the types that don’t have conflicting identity. I believe this processing essentially mirrors what is available to the end user in the UI in a similar situation.

 

Thank you

 

Arnošt Löbel

Autodesk, Revit R&D

Arnošt Löbel
0 Likes
Message 3 of 8

Anonymous
Not applicable
Thanks arnostlobel,
when I use Transfer project standards with the UI, revit will give a message when a imported style is already present in the destination document, leave the user with the choice to overwrite or make a copy. In the API the default behavior is to make a copy, but I want to overwrite and NOT make a copy. Can this be done by the API and how ?
0 Likes
Message 4 of 8

arnostlobel
Alumni
Alumni

Hello Mr. van den Bor,

 

I am afraid that is not yet possible via the API. The methods for copying elements between two documents have just those options for either cancelling the operation or skipping the duplicates. And the API for project standards transfer has not been fully implemented yet. Until we have it released (no date has yet been set though) I suppose you could implement some kind of a workaround that would perform the action in several steps – first to figure out which types have conflict, then change the names on the incoming ones, before finally applying those brought-over types to all instances of the former types. I understand it does not sound very appealing, but we do not have the real deal yet, unfortunately.

 

Sincerely

 

Arnošt Löbel

Autodesk, Revit R&D

Arnošt Löbel
Message 5 of 8

Anonymous
Not applicable
Okay, thanks a lot. I was afraid there wasn't an easy setting to do so. Looks like the alternative you gave is the only way.
Message 6 of 8

Joe.Ye
Alumni
Alumni

Hi Remy,

According to the above discussion, using the CopyElement() method cannot overwrite existing types.

But I think there is a workround. After using CopyElement() method, you can delete the existing type elements, and rename the newly copied type to the name of the just deleted type.

If the duplicate type is used by instance in the model, after call CopyElement() method, assign the newly copied types to instance which used the duplicate type, and then delete the origin type. Finally rename the type back to the origin name.

Hope this helps,


Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Message 7 of 8

Anonymous
Not applicable

Thanks Joe Ye, In a way that is was your collegue suggested too. Looks like this will be the workaround to go for. 

Message 8 of 8

Anonymous
Not applicable

Hey there is an additional hurdle here, what do you do say if the walls that you want to overwrite are grouped for example?

Is that even possible to set the element type as I usually skip groups, so do dynamo user si know?

0 Likes