Set the viewport "zoom" for parallel perspective

This is also partially a grasshopper question as I am scripting this behaviour in it…

For perspective view in Rhino, one can zoom in and out by changing the lens length parameter. This does not work in parallel mode. I looked around for a parameter (including in rhino.display.rhinoviewport) that would be the equivalent for scaling or zooming in parallel mode but I can’t find how to do it.

For context I have a grasshopper script that manipulates the camera position, this works fine but since I want it in parallel mode, the user is required to manually zoom in/out to suit the scene.

Hi @YCoCg,

To zoom in/out of viewport with a parallel projection, try using RhinoViewport.Magnify.

– Dale

2 Likes

Is there a way I can set an absolute scale?

I found a method in rhinoscript called ViewRadius, this seems to do it though if there are any other ways it’d be good to know.

Hi @YCoCg,

Maybe this?

#! python3
import Rhino
import System
import scriptcontext as sc

def ViewportRadius(viewport):
    if viewport and viewport.IsParallelProjection:
        vpinfo = Rhino.DocObjects.ViewportInfo(viewport)
        return System.Math.Min(vpinfo.FrustumRight, vpinfo.FrustumTop)
    return 0

def SetActiveViewRadius(new_radius):
    if new_radius > 0.0:
        view = sc.doc.Views.ActiveView
        if view and view.ActiveViewport.IsParallelProjection:
            old_radius = ViewportRadius(view.ActiveViewport)
            if old_radius > 0.0:
                d = 1.0 / (new_radius / old_radius)
                view.ActiveViewport.Magnify(d, False)
                view.Redraw()
    
if __name__=="__main__":
    SetActiveViewRadius(10.0)

– Dale