How to save a view in another .rvt file

How to save a view in another .rvt file

Anonymous
Not applicable
1,243 Views
13 Replies
Message 1 of 14

How to save a view in another .rvt file

Anonymous
Not applicable

Hello, 
I'm a student in automation and I have to create a REVIT plugin for my internship.
i'm using revit 2021. Is that possible to create a C# plugin to save a view in a different .rvt file ?

how can I save that ?

 

Thank you in advance.

 

0 Likes
1,244 Views
13 Replies
Replies (13)
Message 2 of 14

franciscopossetto
Advocate
Advocate

Hey,

 

When you say save a view, you mean replicate the View element, with all their properties or save the drawing you are seeing on the view?

 

Views in Revit show you the model, if you don't have the model in your other file, you will see an empty view.

If you just need the drawing you could create a drafting view and then transfer it to another document.

 

Does it make sense?

Kind regards.

Github:
https://github.com/franpossetto
Message 3 of 14

3dimdev
Enthusiast
Enthusiast

You can 'copy and paste' elements between documents, including views.  A good starting point is here on Jeremy's blog

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

 

But as @franciscopossetto noted, if it's a view of model elements, you'll need to copy those elements as well.

3rd Dimension Developer
YouTube.com/@3DimDev
0 Likes
Message 4 of 14

Anonymous
Not applicable

Hi,

Thank you for your answer. I would like to save the view with all the elements and their properties. 

I'm working with this code that allow me to save the entire project in another rvt file :

 

 

using Autodesk.Revit.DB;using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;

using System.Net;
using System.IO;
using Newtonsoft.Json;

namespace Lab1PlaceGroup
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class Class1 : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Get application and documnet objects
            UIApplication uiapp = commandData.Application;
            Document doc = uiapp.ActiveUIDocument.Document;
            doc.SaveAs("C:\\Users\\BE117785\\Desktop\\EZIO\\test.rvt");

            return Result.Succeeded;
       }

    }
}

 

 

Now, the goal is to do the same with the different floor views and all their properties.

 

Kind regards,

Ezio Coelho 

 

0 Likes
Message 5 of 14

Anonymous
Not applicable

hello,
thank you  @3dimdev  for you answer. I'm going to have a look at this page. 

 

kind regards,

Ezio Coelho

0 Likes
Message 6 of 14

franciscopossetto
Advocate
Advocate

Hey,

 

You no longer need to copy the view if you duplicate the file because the view is already there. 

 

Does it make sense?

Kind regards.

Github:
https://github.com/franpossetto
0 Likes
Message 7 of 14

Anonymous
Not applicable

Hello @franciscopossetto 

It makes sense because i need  a different file for each floor with all the properties and the element this floor contains.

 

kind regards,

Ezio Coelho

 

0 Likes
Message 8 of 14

franciscopossetto
Advocate
Advocate

Hey @Anonymous 

 

In that case, after duplicating the file you could delete all views except the one you want to preserve. The result will be a new model that just has 1 view.

 

Kind regards.

Github:
https://github.com/franpossetto
0 Likes
Message 9 of 14

Anonymous
Not applicable

Dear @franciscopossetto 

I want to do exactly the same as i do when i do :

- Select a drafting view in the Project Browser.

- Right-click the view name, and click Save to New File.

- Enter a new name for the project. This creates a new Revit project file that contains the selected view and the contents of that view.

but instead of doing this manually whit all my views , I need to create a plugin that does this automatically.

Kind regards,
Ezio Coelho

0 Likes
Message 10 of 14

3dimdev
Enthusiast
Enthusiast

You are almost there!  Just create a new document, use the copy-paste API from the link I provided on The Building Coder blog to copy the view, then save the new document.

3rd Dimension Developer
YouTube.com/@3DimDev
0 Likes
Message 11 of 14

Anonymous
Not applicable

hi @3dimdev ,

I tryed to copypaste the document but I have this error. Can you help me ?

in the picture you have the code I used. 

Kind regards

Ezio Coelho 

he303669_0-1615573993373.png

 

0 Likes
Message 12 of 14

3dimdev
Enthusiast
Enthusiast

Hello @Anonymous ,

The collector is gathering elements visible in a view.  Then when duplicating those elements to a new document, the error states that some of the elements are 'view-specific'.  In Revit terms, this means they belong to a view, not the model.  Makes me think they need to be pasted onto a view, not just to the document in general.  Check out all the overloads of the `ElementTransformUtils.CopyElements()` method.  One of them allows copying from a source view to a destination view.

3rd Dimension Developer
YouTube.com/@3DimDev
0 Likes
Message 13 of 14

Anonymous
Not applicable

Hi @3dimdev ,

Thank you for your answer. I tryed the `ElementTransformUtils.CopyElements()` method  that allows copying from a source view to a destination view. But I have this error now :

he303669_0-1615801622374.png

I think it is because the newDoc I created is not opened so it doesn't have an "activeView" and because of that the "destinationView" is null . how can i choose one of the views of my newDoc ? 

 

Kind regards.

Ezio Coelho

0 Likes
Message 14 of 14

RPTHOMAS108
Mentor
Mentor

The newDoc isn't a UIDocument so I assume that is why it doesn't have an ActiveView. Probably you need to have a specific view in mind by filtering for it (both views should be 2D for this method).

 

I believe you will also need to start a Transaction for the Document you are making changes to.

0 Likes