Save a detailed view to a new file -- using Revit API

Save a detailed view to a new file -- using Revit API

hycA5VF6
Observer Observer
363 Views
4 Replies
Message 1 of 5

Save a detailed view to a new file -- using Revit API

hycA5VF6
Observer
Observer

Hi, 

We are trying to copy an arbitrary detail view (not drafting view, but a detailed view) from a Revit document into a destination Revit document. 

 

We did some research and found solutions such as :

https://forums.autodesk.com/t5/revit-api-forum/copying-all-elements-from-existing-document-to-new-do...

 

and 

https://boostyourbim.wordpress.com/2013/09/01/copy-a-sheet-from-one-project-to-another/

 

However, when we implemented those solutions, 

the detail view is copied to the new document, but it is always empty  when we checked the copied view. 

(View specific elements are copied as per links above) 

 

 

Ideally we want the detail view to be copied to an empty destination file similar to this feature on Revit UI:

 

Can you let us now how do we implement something similar to this feature on the Revit UI using the Revit API ? 

 

Save to New File

 

0 Likes
364 Views
4 Replies
Replies (4)
Message 2 of 5

ctm_mka
Collaborator
Collaborator

Question, with the code you tried, is the view truly empty, or have the detail elements been shot off into space (if you uncrop the view, are they somewhere far from the crop boundary)?

0 Likes
Message 3 of 5

Moustafa_K
Collaborator
Collaborator

I think your approach is correct, but can't judge without reading your code implementation.

but it is important to ensure you are separating the commits between copying the view and copying the content of the view. 

 

see this pseudo implementation: [probably putting all inside a Transaction group is more elegant]

 var trans = new Transaction(targetDoc, "copy Detail View");
 trans.Start();
 var copied = ElementTransformUtils.CopyElements(
     sourceDoc,
     [UiDoc.ActiveGraphicalView.Id],// the source drafting view
     targetDoc,
     Transform.Identity,
     new CopyPasteOptions()
 );
 trans.Commit();

 trans.Start();
 var ids = new FilteredElementCollector(sourceDoc, UiDoc.ActiveGraphicalView.Id) // the source drafting view
     .ToElementIds()
     .ToList();
 ElementTransformUtils.CopyElements(
     UiDoc.ActiveGraphicalView, // the source drafting view
     ids,
     targetDoc.GetElement(copied.First()) as View,
     Transform.Identity,
     new CopyPasteOptions()
 );
 trans.Commit();

 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 4 of 5

hycA5VF6
Observer
Observer

Hi, our code closely resembles these 2 sources:
https://stackoverflow.com/questions/77581058/revit-api-copy-elements-duplicates-view
https://boostyourbim.wordpress.com/2013/09/01/copy-a-sheet-from-one-project-to-another/

Where we first copy the view from src to dest Revit document, 

then get all the elements owned by the view (using FilteredElementCollector.OwnedByView()) in the source document

and copy them into the destination view in the other document. 

 

 

Please let us know if this strategy should work. Thanks

0 Likes
Message 5 of 5

Moustafa_K
Collaborator
Collaborator

that is exactly what i mentioned in my answer. the idea is, you must have a view first, then you can copy the associated elements to that view you just copied. you can't make both at once. 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes