Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Set Rhino camera using GHPython.
"""
Sets Rhino camera from starting location, target location and lens length.
Args:
S: Starting location.
T: Target location.
L: Lens length.
"""
ghenv.Component.Name = "Set Camera"
ghenv.Component.NickName = 'SetCam'
# Import libraries.
import Rhino
import Grasshopper as gh
# Warnings.
if not S:
msg = "Input parameter 'S' failed to collect data."
ghenv.Component.AddRuntimeMessage(gh.Kernel.GH_RuntimeMessageLevel.Warning, msg)
if not T:
msg = "Input parameter 'T' failed to collect data."
ghenv.Component.AddRuntimeMessage(gh.Kernel.GH_RuntimeMessageLevel.Warning, msg)
if not L:
msg = "Input parameter 'L' failed to collect data."
ghenv.Component.AddRuntimeMessage(gh.Kernel.GH_RuntimeMessageLevel.Warning, msg)
# Optional: Set Rhino viewport to alter.
views = Rhino.RhinoDoc.ActiveDoc.Views.GetViewList(True, False)
Rhino.RhinoDoc.ActiveDoc.Views.ActiveView = views[0] # Choose VP here.
# Set camera.
if S and T:
vp = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport
vp.PushViewProjection()
vp.Camera35mmLensLength = L
vp.CameraUp = Rhino.Geometry.Vector3d.ZAxis
vp.SetCameraLocation(S, False)
vp.SetCameraDirection(T - S, True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.