Change Named View in large number of Layouts / Detail Views

I’m lost with an attempt to change a large number of Detail Views all at once. I have a script from @willem which is useful when I’m working page after page.

I found the script by @Dale to change all Detail View modes to Wireframe but I had no luck so far with the additions I made.

What needs to be done to change the view in each detail to its matching Named View?

For now, there are equal numbers of layouts and Named Views.

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc

namedviews = rs.NamedViews()


# Demonstrates how to set all detail views to wireframe display
def SampleSetDetailsToWireframe():
    # Find the wireframe display mode object
    display_mode = Rhino.Display.DisplayModeDescription.FindByName("Wireframe")
    if display_mode:
        # Get all of the document's page views
        page_views = sc.doc.Views.GetPageViews()
        if page_views:
            # Process each page view
            for page_view, namedview in zip(page_views, namedviews):
                print page_view
                
                # Get all of the page view's details
                details = page_view.GetDetailViews()
                print details
                print namedview
                if details:
                    # Process each page view detail
                    for detail in details:
                        # If the detail's display mode is not wireframe...
                        if detail.Viewport.DisplayMode.Id != display_mode.Id:
                            # ...set it to wireframe.
                            detail.Viewport.DisplayMode = display_mode
                            detail.CommitViewportChanges()
                    # Redraw the page view
                    page_view.Redraw()
    
# Check to see if this file is being executed as the "main" python
# script instead of being used as a module by some other python script
# This allows us to use the module which ever way we want.
if __name__ == "__main__":
    SampleSetDetailsToWireframe()

restore_named_views.py (1.6 KB)

Hi Martin,

Did you get this solved somehow?
I have this post bookmarked but never get around to replying with a useful answer.

Just wanted to check in if you are still in need of help

-Willem

Thanks for the reply @Willem.

I ended up changing the named views page after page.

Attached is a Rhino file where I tried to update a detail with the script posted above but it doesn’t change the named view.

I often have large number of layouts and I’m wondering what needs to be done so the script changes my named views.

22_01_31_test.3dm (1.6 MB)

restore_named_views.py (1.6 KB)

Hi Martin,

I wrote some code that seema to work, however I’m not sure what the relation between the pages/details and the named views is.

In other words: What s the rule to know what detail needs what named view?

-Willem

The detail on page 00 shows the volume_01_B

volume_01_B is the layer name and there is a named view with the same name.

How can ‘the code’ know that relation?

In other words:
if I have the detail on page 00, what is the logic the code should follow to know it should restore the named view volume_01_B?

Especially since the other pages do not seem to have such explicit relation.

The other pages also have relations.

I think of a list A with layer names and a list B with all the details / pages.

There’s a named view for every layer.

So the code should first get that list to know the relations between the pages and the named views?

How about naming the detail object the same as the named_view?

The code I have is working in restoring named views to details, what is missing is the logic how to match named views to each detail.

Those would be two lists with the same length.

And would they be hardcoded in the script or external files?

I think of two lists / inputs in Grasshopper.

I will use this script in Grasshopper

This is what I came up with so far, not sure about integrating it in GH

restore_detail_named_views.py (1.5 KB)

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc


def restore_named_view(page_view, detail, named_view):
    
    sc.doc.Views.ActiveView = page_view
    page_view.SetActiveDetail(detail.Id)
    
    index = sc.doc.NamedViews.FindByName(named_view)
    viewinfo = sc.doc.NamedViews[index]
    
    av = sc.doc.Views.ActiveView.ActiveViewport
    av.PushViewInfo(viewinfo, False)
    
    sc.doc.Views.Redraw()
    page_view.SetPageAsActive()
    sc.doc.Views.Redraw()


def page_details_to_namedview(match_dict):
    
    namedviews = rs.NamedViews()
    
    # Get all of the document's page views
    page_views = sc.doc.Views.GetPageViews()
    if page_views:
        # Process each page view
        for page_view in page_views:
            #check if page in dictionary
            if page_view.PageName in match_dict.keys():
                named_view = match_dict[page_view.PageName]
                if named_view in namedviews:
                    # Get all of the page view's details
                    details = page_view.GetDetailViews()
                    if details:
                        # Process each page view detail
                        for detail in details:
                            restore_named_view(page_view, detail, named_view)


if __name__ == "__main__":
    
    match_dict = {'00': 'volume_01_B',
                  '01': 'Top_01',
                  '02': 'Top_02',
                  '03': 'Top_03'
                  }
    
    page_details_to_namedview(match_dict)
2 Likes

Thanks for your help, that seems to work :slight_smile: