Go to view section

Go to view section

stever66
Advisor Advisor
2,760 Views
6 Replies
Message 1 of 7

Go to view section

stever66
Advisor
Advisor

In Revit, I can select a view section, right click, and select "Go To View".

 

Is it possible to do this with the API?  If so, can someone post an example, or the necessary code?

 

I've searched a couple of places, but came up empty.  I've found the "ViewSection" class, but nothing stands out as an obvious "GoTo" command?

 

I've also found the ReferencableViewUtils.GetReferencedViewId.  If there isn't an easier way, can that be used to open a section view?

 

Thanks.

 

0 Likes
Accepted solutions (1)
2,761 Views
6 Replies
Replies (6)
Message 2 of 7

aignatovich
Advisor
Advisor
Accepted solution

Hi!

 

You should first of all retrieve the view, you want to "go to" for example, using FilteredElementCollector, then just set UIDocument.ActiveView property with the view, that you retrieved.

0 Likes
Message 3 of 7

jeremytammik
Autodesk
Autodesk

There are two ways to approach this (at least).

 

Here is a recent discussion of them:

 

http://thebuildingcoder.typepad.com/blog/2018/03/switch-view-or-document-by-showing-elements.html

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 4 of 7

stever66
Advisor
Advisor

Ok, but lets say I have a section line selected when I run my code.  When the code is executed, I have access to the section line which is an element.  That is, I have its ElementID.

 

How do I get a variable that refers to the section view from the section element?

0 Likes
Message 5 of 7

jeremytammik
Autodesk
Autodesk

First, take a look at the section line and its properties in RevitLookup.

 

You may well discover that the element id of the view is tucked away somewhere in there.



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 6 of 7

stever66
Advisor
Advisor

I'm still at a loss.  I'm not a programmer, so without an example line of code, all I can do is guess.

 

I have no idea how to convert whatever type of parameter I get from the section mark to a variable that can represent a view.  Spent a couple of hours trying different things and searching online for a simple example of a line of code that opens a view.

 

This is what I have tried so far:

 

        public void OpenSection()
        {
            
            UIDocument uidoc = ActiveUIDocument;
            Document doc = ActiveUIDocument.Document;
            Autodesk.Revit.DB.View pView = ActiveUIDocument.Document.ActiveView;
            
            Selection selection = uidoc.Selection;
            ICollection<ElementId> selectedIds = uidoc.Selection.GetElementIds();
                 
           IList<View> selected = new List<View>();
                 
                         
                         foreach (ElementId id in selectedIds)
                        {
                            //TaskDialog.Show("Revit", "Start Loop");   //Made it this far
                            Element e = doc.GetElement(id);   
                            TaskDialog.Show("Revit", e.Name.ToString());   //find the name of the section
                            Parameter pr = e.LookupParameter ("Referenced View");
              
                            using( Transaction tx = new Transaction(doc) )
                                      {
                                    tx.Start"Open Section" );
                                    //uidoc.ActiveView.get_Parameter(e.LookupParameter(BuiltInParameter.REFERENCED_VIEW));  //wont build
                                    //uidoc.ActiveView = uidoc.get_Parameter(e.LookupParameter(BuiltInParameter.REFERENCED_VIEW));  //wont build
                                    //uidoc.ActiveView = pr as View;  //Cant convert this
                                    //uidoc.ActiveView = pr;  //THis doesn't work:  cannot implicity convert type 'Autodesk.Revit.DB.Parameter' to 'Autodesk.Revit.DB.View'
                                    //uidoc.ActiveView.get_Parameter(e.LookupParameter ("Referenced View"));  //this doesnt work
                                    
                                    ViewSection viewsection = new ViewSection();
                                    viewsection.Name = pr.ToString();
                                    uidoc.ActiveView = viewsection;
                                    tx.Commit();
                                    uidoc.RefreshActiveView();

                                    }
                   
                         }
            
         } //end OpenSection

0 Likes
Message 7 of 7

stever66
Advisor
Advisor

Nevermind.  I found a sample of code that works, although in a somewhat more round about way.  Still uses the filtered element collector to get the view section by filtering out the same one that is selected.

 

 

0 Likes