Layout Detail View, Set to Named View

@dale I am trying to copy a layout and set the first detail on the copied layout to a named view. I am not able to set the detail to the named view. Please see an example below. (The example must be run, while the layout to copy is visible.). Thanks for your help.

#! python3
import Rhino
import scriptcontext as sc


def main():
    source_layout = sc.doc.Views.ActiveView
    duplicate_layout = source_layout.Duplicate(True)
    duplicate_layout.PageName = "Layout002"

    detail_view = duplicate_layout.GetDetailViews()[0]
    named_view_index = sc.doc.NamedViews.FindByName("NamedView002")

    # This is not working as intended, does nothing
    sc.doc.NamedViews.Restore(named_view_index, detail_view.Viewport)
    sc.doc.Views.Redraw()


main()

Untitled.3dm (93.5 KB)

Untitled.py (436 Bytes)

@BrianJ May you suggest who might help me with this one. I am stuck and we are working towards a deadline. To give some context: I need to apply custom plan headers with variable attributes to hundreds of layouts while using different named views on the generated layouts. I am not able to figure a usable workaround. Many thanks!

@eirannejad Any thoughts?

1 Like

Hi @silvano,

Your code seems reasonable.

For now, just script the NamedView command.

#! python 3
import Rhino
import scriptcontext as sc

def TestCopyLayout():
    layout = sc.doc.Views.ActiveView
    if not isinstance(layout, Rhino.Display.RhinoPageView):
        print("A layout view must be the active view")
        return

    duplicate_layout = layout.Duplicate(True)
    duplicate_layout.PageName = "Layout002"
    sc.doc.Views.ActiveView = duplicate_layout

    detail_views = duplicate_layout.GetDetailViews()
    detail_views[0].IsActive = True
    Rhino.RhinoApp.RunScript("_NoEcho _-NamedView _Restore NamedView002 _Enter", False)
    detail_views[0].IsActive = False
    sc.doc.Views.Redraw()

if __name__ == "__main__":
    TestCopyLayout()

– Dale

1 Like

@dale Many thanks, I should have thought of that as a workaround :distorted_face:

Long term, I would still be interested in getting the rhinocommon solution to work. We seem to need this quite frequently and I would like to add it as a custom command to our office library. If you might have any pointers as to why my code does not work, it would be greatly appreciated.