Behavior of ElementTransformUtils.CopyElements when copying an external RVT view

Behavior of ElementTransformUtils.CopyElements when copying an external RVT view

homer_anave
Contributor Contributor
1,123 Views
5 Replies
Message 1 of 6

Behavior of ElementTransformUtils.CopyElements when copying an external RVT view

homer_anave
Contributor
Contributor

This is what I have observed when using ElementTransformUtils.CopyElements when I am about to copy a view from another Revit document to my currently opened Revit document.

 

1.) Views are collected using FilteredElementCollector from the external document, brought to a window in a list, and collect only selected views.

2.) Per each selected view, get Ids of all elements present (in this case, it is a drafting view), then use CopyElements and intend to copy these elements in a new drafting view from the current document.

3.) All modification processes committed, and application returned Successful.

4.) Nothing has been copied to the new drafting view, but the selected views from the other Revit document were copied into the current document.

 

Is this really the behavior of this method, or the result when using this method?

Also, is anyone here had a success in using CopyElements and were able to copy elements into a new view?

0 Likes
1,124 Views
5 Replies
Replies (5)
Message 2 of 6

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @homer_anave ,

Search for "Duplicate Views" in the SDK sample.

I think that will help you to solve this problem.

 

https://thebuildingcoder.typepad.com/blog/2013/05/copy-and-paste-api-applications-and-modeless-asser... 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 6

homer_anave
Contributor
Contributor

Thank you very much for the reply.

 

That is exactly what I did even in the previous program that I made. It only copies the views from a source document and pastes on the destination document (in my case, the current document). However, it does not copy the elements into the DESTINATION VIEW of the destination document, which I wanted and expected especially the below CopyElements function to do.

 

ElementTransformUtils.CopyElements(View, ICollection<ElementId>, View, Transform);

 

Or did I miss something essential while doing this?

 

Additionally, the above function eventually opens all the views that it copied. I wanted to close these views, but I couldn't because the views open once the command has finished (and I can't think of a way to intercept this process, and even through UIView did not help). Is there a way I can close these views?

0 Likes
Message 4 of 6

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @homer_anave ,

Follow these steps

1)Start a transaction for your source document

2)Start a transaction for your destination document

3)Create a list and add the elements from the source document to the list. Now you will have a list of elementids to copy

4)filter for the view to which you want to copy the element and get the view. Now you will have source view and destination view

5)Now use ElementTransformUtils.CopyElements(sourceview,IList<elementid>,destinationview,transform,CopypasteOption) to place the elements to the desired view of new document.

 Document activedoc;
 Document newdoc;

//List of Elements to copy
 IList<ElementId> eids = new List<ElementId>();

 CopyPasteOptions CPO = new CopyPasteOptions();
 CPO.SetDuplicateTypeNamesHandler(new CopyUseDestination());

//Get the required view from new document
Autodesk.Revit.DB.View newView = null;
FilteredElementCollector collector = new FilteredElementCollector(newdoc).OfClass(typeof(Autodesk.Revit.DB.View)).WhereElementIsNotElementType();
foreach(Autodesk.Revit.DB.View v in collector)
 {
   if(v.Name.Contains(activedoc.ActiveView.Name))
       {
         newView = v as Autodesk.Revit.DB.View;
         break;
        }
   }

//Copy ELEMENTS
 ElementTransformUtils.CopyElements(activedoc.ActiveView,eids,newView,Transform.Identity,CPO);

6)commit destination document transaction

7)commit source document transaction

 

 

 I hope this helps.

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 6

MiguelGT17
Advocate
Advocate

What is the code for 

new CopyUseDestination()

I don't see it as an Revit api class component. Could you guys elaborate that implementation?  

0 Likes
Message 6 of 6

anave_homer_ps
Community Visitor
Community Visitor

Hello, Miguel.

 

This reply is a way long overdue already. But in case you haven't still figured this out, it is just a sample of a class that is derived from IDuplicateTypeNamesHandler interface.

 

Hope this helps.

0 Likes