Adjusting the camera lens length in python

Hi there

I am trying to figure out how to use an item in the scriptcontext library. I have my camera location and target set using

vp = sc.doc.Views.ActiveView.ActiveViewport
vp.SetCameraLocation(loc, False)
vp.SetCameraDirection(tar - loc, True)

what variables do I need to pass in in order to use

sc.doc.Views.ActiveView.ActiveViewport.Camera35mmLensLength() ?

python has been throwing multiple errors with whatever I try. Also, is there an online reference library for scriptcontext? I can’t seem to locate it.

Cheers

Hi Daniel,

You need to set the value to Camera35mmLensLength property:

import rhinoscriptsyntax as rs
import scriptcontext as sc

vp = sc.doc.Views.ActiveView.ActiveViewport
vp.Camera35mmLensLength = 43
rs.Redraw()
1 Like

scriptcontext is a reference to the active document, it’s objects and attributes. Thus most of the functions can be found in classes like Rhino.Display, Rhino.DocObjects, Rhino.DocObjects.Tables, etc.

For example
sc.doc.Views.ActiveView.ActiveViewport

is the equivalent of

Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport

Rhino.RhinoDoc.ActiveDoc.Views references the current document’s view table, all of the methods and properties for dealing with those can be found under Rhino.Display.RhinoViewport… It’s a little hard to find your way around at the beginning.

I use the online SDK as a reference, but it’s also all in the editor left sidebar.

A handy tool I made is below - it will save a text file with all the subdirectories (subclasses?) of a particular class… For example, to see what’s in scriptcontext.doc.Objects you would run the following:

import rhinoscriptsyntax as rs
import scriptcontext as sc
iClass=sc.doc.Objects
direc=dir(iClass)

def ExportClassDirectory(direc):
    filter = "Text File (*.txt)|*.txt|All Files (*.*)|*.*||"
    filename = rs.SaveFileName("Save directory as", filter)
    if not filename: return
    namext=filename.split("\\")
    name=namext[-1].split(".")
    
    file=open(filename,"w")
    file.write(name[0]+"\n\n")
    for item in direc:
        file.write(item+"\n")
    file.close()

ExportClassDirectory(direc)

–Mitch

2 Likes

Thanks guys!!! Super helpful info! Appreciate it.