Last active
June 11, 2023 08:55
-
-
Save StepMaher/d3c3b67001e53e456e4c to your computer and use it in GitHub Desktop.
Set Rhino camera using GHPython.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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