Capture View with Rectangle

Thanks to @liukov.dobriev and his script from this threat.
Although I’m fully newbie to scripting, lately I was trying to modify it a bit it can capture selected view (Top/Front/Right).

However, since the script use rectangle’s X,Y to define its size. It no longer works when the view plane is not on XY plane…

Any idea and help will be appreciated!

Set specific print (94.3 KB)

not an expert in scripting, but looks like you want to change these two variables that get the XY size of the frame:

if you are in Top view, then X Y are ok as they represent the following:

if for instance you want to get the right view, then you’ll need the Y Z dimensions


so the code might be something like this:

Set specific print (97.8 KB)

Hi @inno Thnkas for the reply,

Yes I’ve been aware the XYZ issue when the views are different.
So I guess the script has to be more intuitive.
For example,

if view=Top, px, py = set(frame.X), set(frame.Y)
if view=Front, px, py = set(frame.X), set(frame.Z)
if view=Right, px, py = set(frame.Y), set(frame.Z)

So I somewhat modified the script as show below.
Note that the input curve is meant to parallel to the correspond view plane.
As I mentioned at first I’m really new to scripting…all I did is shuffle and messing around in the script.
One thing I noticed is Redraw in the script seems take a bit of time.

Please give any suggestion or thought if anywhere I can improve, I’ll be very appreciated. (103.1 KB)

import Rhino
import System.Drawing
import Rhino.Geometry as rg
import scriptcontext as sc
import rhinoscriptsyntax as rs
import Rhino.Display as rd
import System

pt0 = frame[0]
pt1 = frame[1]
pt2 = frame[2]
pt3 = frame[3]

width = rg.Point3d.DistanceTo(pt0, pt1)
height = rg.Point3d.DistanceTo(pt1, pt2)

size = 'w=' + str(int(width*fector)) + ', ' + 'h=' + str(int(height*fector))

def Capture():
    RhinoDocument = Rhino.RhinoDoc.ActiveDoc
    selectview = RhinoDocument.Views.Find(view, False)
    size = System.Drawing.Size(int(width*fector),int(height*fector)) 

    settings = rd.ViewCaptureSettings(selectview, size, 300) #view, size, dpi
    settings.SetWindowRect(pt0, pt2)
    settings.RasterMode = True
    settings.DrawGrid = False
    settings.DrawAxis = False
    settings.DrawWallpaper = False

    bitmap = rd.ViewCapture.CaptureToBitmap(settings)

if save:
    RhinoDocument = Rhino.RhinoDoc.ActiveDoc
    selectview = RhinoDocument.Views.Find(view, False)
    rs.ViewDisplayMode(view, mode)

Hi Ctu6
thanks for your idea! I have implement it in my side. However, there is a error show up!(in the following image). does anyone have the idea how to solve this
(I am quite new about scripting, maybe it just a problem related to the Rhinoceros setting environment)