Cropping with scripting


I am using this piece of code for zooming in an object until its border

rs.Command('_-SetZoomExtentsBorder _ParallelView=1 _Enter')

and then exporting it to an image

rs.Command("_-ViewCaptureToFile " + chr(34) + imagePath +chr(34) + " _EnterEnd")

the problem is that it zooms only 2 sides and I would like to zoom all 4 sides of the picture.

How to do that?

Thank you

Hello - you’d need to do some more work - set the viewport size to the aspect ratio of the objects in that view. I’ll see if I can figure something out that helps.


Ok thanks

@hansalbi, something like this:

import rhinoscriptsyntax as rs

def test():
    ids = rs.AllObjects()
    if not ids: return
    bb = rs.BoundingBox(ids, rs.ViewCameraPlane(),False)
    bbX = rs.Distance(bb[0], bb[1])
    bbY = rs.Distance(bb[0], bb[3])

    bbRatio = bbX/bbY
    size = rs.ViewSize()
    w = size[0]; h = size[1]

    if bbX > bbY:
        w = size[0]; h = size[0]/bbRatio
    elif bbX<bbY:
        w = size[1]*bbRatio; h = size[1]
        if bbRatio < 1:
            w = size[0]*bbRatio; h = size[1]
        elif bbRatio > 1:
            w = size[0]; h = size[1]*bbRatio
    rs.Command("_-ViewportProperties Size " + str(int(w)) +" " + str(int(h)) + " _EnterEnd")



Hello Pascal,
still not working as expected.

I’ve sent a PM to you with the code I’m curretly using.