Grasshopper Python script to restore named view in detail

I’m trying to automate the export of a lot of plans with objects that Benefit from different perspective views. Thus, I’m creating Named Views manually

I thought I could use RestoreNamedView to set the view in a detail but I don’t understand how to address the detail view.

It works manually if I go to the layout, double click the Detail, then double click the named view Thumbnail in the Rhino Named View panel but that’s going to be Pretty tiring…

Can anyone help me please?

Hi,

Not sure if this can work from within GH but fwiw a quick hack:

import rhinoscriptsyntax as rs
import scriptcontext as sc


#find views on current layout


def get_current_layout_details():
    current =  sc.doc.Views.ActiveView.MainViewport
    current_id = current.Id
    print current_id
    
    current_details = []
    detail_ids = rs.ObjectsByType(32768)
    for detail_id in detail_ids:
        robj = rs.coercerhinoobject(detail_id)
        if robj.Attributes.ViewportId == current_id:
            pass
            current_details.append(detail_id)
    return current_details
    


for detail_id in  get_current_layout_details():
      #here you can check name or other attributes of the detial object
      #to maybe choose the view to restore
      
      namedview = 'testname'
      
      rs.UnselectAllObjects()
      rs.SelectObject(detail_id)
      rs.Command('Detail Enable _Enter')
      rs.Command('-NamedView Restore "{}" _Enter'.format('testname'))
      rs.Command('Detail EnablePage _Enter')
      rs.UnselectAllObjects()

Sick! That works! Thank you so much!