Thank you so much @AndyPayne ! I was hoping it was this simple but couldn’t figure out how to make the view info work for me.
Much appreciated!
Here’s the code I ended up with:
import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
CVs = Rhino.RhinoDoc.ActiveDoc.NamedViews
Current_View_Names = []
for cv in CVs:
Current_View_Names.append(cv.Name)
def bake_views():
for name, view in zip(N, V):
# Get/Set Viewport Info
viewport = Rhino.Display.RhinoViewport()
viewport.Name = name
viewport.SetViewProjection(view, False)
if name in Current_View_Names:
# Check If The Existing Named View Has Changed Camera Position At All
exv_index = CVs.FindByName(name)
existing_view = CVs[exv_index]
if existing_view.Viewport.CameraLocation != view.CameraLocation and existing_view.Viewport.CameraDirection != view.CameraDirection:
# Remove existing view
sc.doc = Rhino.RhinoDoc.ActiveDoc
rs.DeleteNamedView(name)
# Add the new view
Rhino.RhinoDoc.ActiveDoc.NamedViews.Add(Rhino.DocObjects.ViewInfo(viewport))
#Refresh The Viewport If It Is Currently The Modifed View
if rs.CurrentView() == name:
rs.RestoreNamedView(name)
sc.doc = ghdoc
else:
# Add View(s) To Document
Rhino.RhinoDoc.ActiveDoc.NamedViews.Add(Rhino.DocObjects.ViewInfo(viewport))
return V
if B:
bake_views()
I expanded the code to accept a boolean allowing it to be “active” and if a named view does not exist, it adds it, if a named view camera changes its position, it updates the current named views by deleting the changed views and readding it. Ideally I would like to keep the view and just modify the required settings but wasn’t having any luck there.
Graph Space:
