Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to implement IDuplicateTypesNameHandler, for the CopyPasteOptions Class?

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
miguel.alanis
2220 Views, 2 Replies

How to implement IDuplicateTypesNameHandler, for the CopyPasteOptions Class?

Hello,

 

I create a function to load an specific TextType, needed on my addin.

 

Here's what the function does

 

  1. First the function validates that the name of the text type exist on the current project
  2. If it doesn't exist the addin copy from a resource a base Revit project file that contains the text type, and open it.
  3. Once opened it search for the TextType and copied with the method ElementTransformUtils.CopyElements to the current Revit Project.
  4. Finally the base Revit project is closed

It works fine, but each time the TextType is copied I received a warning message saying the following Types already exist but are different.

And show the following details

Arrow 30 Degree

Arrowhead: Arrow 30 Degree.

 

Since I'm not copying those elements I would like to remove the message.

 

Searching on the Revit documentation I found that the CopyPasteOptions could remove it, using the SetDuplicateTypeNamesHandler method that uses IDuplicateTypeNamesHandler, but I haven't found how to implement that interface.

 

I'll appreciate any help

Thanks

 

Here is the snippet of my function

 

        internal static void LoadTextTypes()
        {
            FilteredElementCollector textNoteTypes = new FilteredElementCollector(Revit_App.RevDef.RevitDoc);
            textNoteTypes.OfClass(typeof(TextNoteType));
            var type = from text in textNoteTypes
                       where text.Name == "Vialdi Text"
                       select text as TextNoteType;
            if (type.Count() > 0)
                return;
            string path = System.IO.Path.Combine(Revit_App.App.AppDirectory.FullName, "baseProject.rvt");
            System.IO.File.WriteAllBytes(path, Media.BaseProject);
            Document baseDocument = Revit_App.RevDef.RevitApp.OpenDocumentFile(path);
            textNoteTypes = new FilteredElementCollector(baseDocument);
            textNoteTypes.OfClass(typeof(TextNoteType));
            type = from text in textNoteTypes
                   where text.Name == "Vialdi Text"
                   select text as TextNoteType;
            List<ElementId> textTypes = new List<ElementId>();
            textTypes.Add(type.First().Id);
            Transaction tra = new Transaction(Revit_App.RevDef.RevitDoc, "copy");
            tra.Start();
            ElementTransformUtils.CopyElements(baseDocument, textTypes, Revit_App.RevDef.RevitDoc, null, new CopyPasteOptions());
            tra.Commit();
            baseDocument.Close();
        }

 

And here is the warning message

Duplicate Tyeps

2 REPLIES 2
Message 2 of 3
arnostlobel
in reply to: miguel.alanis

Hello Miguel Alanis:

 

I believe the problem is caused by the existence of nested families (types) referenced by the text type you attempt to copy. In other words, you do copy a type that does not exist yet, but which contains other nested types that do exists already in the target document, either as standalone or nested in other families.

 

In your particular case it seems you do not worry about that, therefore you should simply set the copy option to ignore such cases, meaning you give it an instance of your custom IDuplicateTypeNamesHandler.

 

CopyPasteOptions options = new CopyPasteOptions();
Options.SetDuplicateTypeNamesHandler(new MyCopyHandler());

 

Where the class MyCopyHandler is an implementation of the IDuplicateTypeNamesHandler, for example:

public MyCopyHandler : IDuplicateTypeNamesHandler
{
   public DuplicateTypeAction OnDuplicateTypeNamesFound()
   {
      return DuplicateTypeAction.UseDestinationTypes;
   }
}

  

(Note: I typed the above code directly in this post just to illustrate the case. Please make sure to adjust it so it compiles 😉

 

Thank you

 

Arnošt Löbel

Sr. Principal Engineer

Autodesk, Revit R&D

Arnošt Löbel
Message 3 of 3
miguel.alanis
in reply to: arnostlobel

Thanks for the solution

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community