Saving Rhino Views

Hello,

One of my good students has faced a strange problem in using a piece of ghPython code previously posted by @mostapha to save views in an annual glare analysis.

He is studying multiple cases and would like to automate saving Rhino Named Views. He has followed a previous post (https://www.grasshopper3d.com/group/ladybug/forum/topics/automatically-create-named-rhino-views-from-grasshopper) and @mostapha was kind enough to post a ghPython code to automatically save the current view.

But he is experiencing what seems to be the same problem as the previous forum poster - The Named View which is saved by this python code appears to be either ‘parallel’ or from the ‘Right’ view rather than from Perspective. He is using the Ladybug Set View component which appears to be working fine, and he thinks it is the ghPython code which is not working correctly.

I have attached the relevant segment of GH definition and a screenshot here. Any help would be greatly appreciated!!

Thanks!


ViewSave.gh (27.6 KB)

1 Like

Hello, I am actually the aforementioned student…

I managed to solve this issue myself by following the Rhino Syntax documentation and thought it might be useful for others to post it here. I rewrote the code as follows:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino as rc
# Firstly delete the existing NamedViews
if Num == -1:
    sc.doc = rc.RhinoDoc.ActiveDoc
    NamedViews = rs.NamedViews()
    for Name in NamedViews:
        rs.DeleteNamedView(Name)
    sc.doc = ghdoc
# Then I use Ladybug fly and Ladybug SetView to iterate through views & Save here, making sure to set active view first
if Num >= 0:
    sc.doc = rc.RhinoDoc.ActiveDoc
    rs.CurrentView(view = View2Save)
    rs.AddNamedView(ViewName, View2Save)
    sc.doc = ghdoc

The key issue was setting the active view before attempting to save NamedViews to ensure it saved the view from the Perspective Viewport.

All the best,

Ryan.

2 Likes