Change Viewport type

Change Viewport type

joaofmoco
Advocate Advocate
1,383 Views
4 Replies
Message 1 of 5

Change Viewport type

joaofmoco
Advocate
Advocate

Hello,

 

I have been working on an addin for Revit 2020 (the same in my previous posts) and now I want to know if there's a way of changing my current code to make viewports with no title and line.

The current code makes 3 viewports in the default style (Title and Line). However, I want a viewport without those elements present.

I want to do this through the API.

Here's the code:

AddViewToSheetCommand.cs:

#region Namespaces
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
#endregion

namespace RevitAddin
{
    [Transaction(TransactionMode.Manual)]
    class AddViewToSheetCommand : IExternalCommand
    {
        public Result Execute(
          ExternalCommandData commandData,
          ref string message,
          ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Application app = uiapp.Application;
            Document doc = uidoc.Document;

            // Filtered Element Collector list for the 3D Views
            List<View3D> all3DViews = new FilteredElementCollector(doc).OfClass(typeof(View3D)).Cast<View3D>().ToList();
            all3DViews.OrderBy(a => a.GetTypeId());

            // Filtered Element Collector list for Sheet Views
            List<ViewSheet> allSheetViews = new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)).Cast<ViewSheet>().ToList();
            allSheetViews.OrderBy(b => b.GetTypeId());

            // Filtered Element Collector list for created Viewports
            List<Viewport> allNewVps = new FilteredElementCollector(doc).OfClass(typeof(Viewport)).Cast<Viewport>().ToList();
            allNewVps.OrderBy(c => c.GetTypeId());

            // Grab created Sheet View
            ViewSheet sheet = allSheetViews.LastOrDefault();

            // Grab all created Views
            View3D v1 = all3DViews[all3DViews.Count - 3];
            View3D v2 = all3DViews[all3DViews.Count - 2];
            View3D v3 = all3DViews[all3DViews.Count - 1];

            // Modify document within a transaction
            using (Transaction tx3 = new Transaction(doc))
            {
                tx3.Start("AddViewToSheet");

                // Add 3 viewports, 1 for each view
                Viewport viewport1 = Viewport.Create(doc, sheet.Id, v1.Id, new XYZ(0.45, 0.45, 0));
                Viewport viewport2 = Viewport.Create(doc, sheet.Id, v2.Id, new XYZ(0.45, 0.75, 0));
                Viewport viewport3 = Viewport.Create(doc, sheet.Id, v3.Id, new XYZ(1, 0.45, 0));

                tx3.Commit();
            }

            return Result.Succeeded;
        }
    }
}

 I have also made available all the code used in this API for testing purposes (Check .zip file bellow)

0 Likes
Accepted solutions (1)
1,384 Views
4 Replies
Replies (4)
Message 2 of 5

Sean_Page
Collaborator
Collaborator

Using Revit Lookup you can see there are properties of the Viewport Types for Show Title and Show Extension Line. You should be able to set those on any existing and/or created Viewport Types

 

spage_0-1650312353615.png

 

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes
Message 3 of 5

joaofmoco
Advocate
Advocate

Hello and thank you for your reply,

 

So, what you are saying is that I should replace the parameter values instead of the Viewport Type?

 

Kind regards,

0 Likes
Message 4 of 5

Sean_Page
Collaborator
Collaborator
Accepted solution

You will need to have a Viewport Type WITH the parameters set as you would like them. If you think about how you would do it in the UI, it would be picking one from the Type Selector that doesn't have the Title or Line. That is the same thing here. You first need a type that doesn't have them ON, then you need to set / change to that type.

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes
Message 5 of 5

joaofmoco
Advocate
Advocate

Hello and thank you for your reply,

 

Your answer makes a lot of sense. By creating a new type of viewport, I can have more control over the viewports created :).

 

Thank you so much!

0 Likes