Camera Setting on Detail

Hi

I am trying to set up a camera with a Namedview on a detail using python.
The way I structured is

  1. setup a camera location, up and target and save as a Named view
  2. Create a layout,
  3. Create a detail,
  4. Change the Camera location, up, target under the detail and then commit changes.

so from task 3) the code looks like

detail = layout.AddDetailView(“dName_{0}”.format(page_number), top_left, bottom_right, Rhino.Display.DefinedViewportProjection.Top)
if detail:
layout.SetActiveDetail(detail.Id)
detail.Viewport.SetCameraLocation(NamedView.CameraLocation,False)
detail.Viewport.SetCameraDirection(NamedVIew.CameraDirection,False)
detail.Viewport.CameraUp = NamedView.CameraUp
detail.CommitChanges()

This is how I change the camera setting.(NamedVIew here is viewportinfo from the saved NamedView)

However, even if the values such as cameraLocation, Direction, and target, are changed, the end layout with the detail is back to the top view.

Or is there a way to move and set a camera under a detail? I am willing to take any suggestions on setting multiple layouts and multiple details with multiple views through scripting.

Thanks,

Nevermind. I figured. Everything worked fine using detail.CommitViewportChanges() before detail.CommitChanges()

And any non-Viewportchages before CommitViewportChanges seems to un-do all the viewport changes.

Thank you.

Hello,

For any others trying to get this to work, please see attached. Written to run in GH.

import Rhino.Geometry as rg
import rhinoscriptsyntax as rs
import scriptcontext
import Rhino

def AddLayout():
    #scriptcontext.doc.PageUnitSystem = Rhino.UnitSystem.Millimeters
    page_views = scriptcontext.doc.Views.GetPageViews()
    page_number = 1
    if page_views: page_number = len(page_views) + 1
    pageview = scriptcontext.doc.Views.AddPageView("TF{0}".format(page_number), 17, 11)
    if pageview:
        top_left = Rhino.Geometry.Point2d(.25,.25)
        bottom_right = Rhino.Geometry.Point2d(16.75, 10.75)
        detail = pageview.AddDetailView("ModelView", top_left, bottom_right, Rhino.Display.DefinedViewportProjection.Top)
        
        if detail:
            pageview.SetActiveDetail(detail.Id)
            #pt is Point3d input in GH    
            detail.Viewport.SetCameraTarget(pt,False)
            detail.Viewport.SetCameraLocation(pt,False)
            
            # Commit changes tells the document to replace the document's detail object
            # with the modified one that we just adjusted
            detail.CommitViewportChanges()
            rs.DetailScale(detail.Id,1,1)
            rs.DetailLock(detail.Id,True)
            detail.CommitChanges()
        
        pageview.SetPageAsActive()
        scriptcontext.doc.Views.ActiveView = pageview
        scriptcontext.doc.Views.Redraw()

if __name__=="__main__":
    AddLayout()