Camera 3Pt Python


(Matt Gaydon) #1

I am trying to write a tool so I can set the camera of a selected view based on 3pts in the same way as a Cplane can be defined. Though I yet to find a way to set the rotation/tilt with out trying to calculate 3D angles to set the rotation. I have found ViewCameraPlane which returns the camera Plane but yet to find a way to reverse engineer this to be able to input a plane.

Any thoughts??

Thanks
Matt


(Matt Gaydon) #2

For anyone interested I have been able to make it work like this, Though it would be great to be able to have a Boolean option when getting view to adjust asking if to SetCPlane but I have not worked out how to add this option in to the RhinoGet.GetView as its does not seem to be customisable.

import rhinoscriptsyntax as rs
from Rhino import Commands
from Rhino.Input import RhinoGet
from Rhino.Display import RhinoView

def Camera3Pt():
    #Get Pts and Define Plane Axis
    pts = rs.GetPoints(False,False,"Set Pts",None,3,None)
    plane = rs.PlaneFromPoints(pts[0], pts[1],pts[2])

    #Set Viewports For Camera
    rc, cam_view = RhinoGet.GetView("Select view to adjust")
    if rc!=Commands.Result.Success: return rc
    cam_view_ID = cam_view.ActiveViewportID

    cam_target = pts[0]
    cam_loc = rs.PointAdd(plane.ZAxis,pts[0])
    
    cam = rs.ViewCameraTarget(cam_view_ID,cam_loc,cam_target )
    cam = rs.ViewCameraUp(cam_view_ID,plane.YAxis)
    rs.ViewProjection(cam_view_ID,1)
    rs.ViewCPlane(cam_view_ID, plane)

Camera3Pt()

p.s how do I paste a code Snippet correctly as seems to only half work this time.??

Camera 3pt.py (791 Bytes)


#3

First, type 3 backticks plus python, then paste in your code, then another 3 backticks after your code:

```python
<paste your code here>
```

–Mitch