#wrote by guev

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
import System.Drawing
import os

def Capture (filePath,width,height):
    RhinoDocument = Rhino.RhinoDoc.ActiveDoc
    view = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView
    size = System.Drawing.Size(width,height)
    capture = view.CaptureToBitmap(size)
    capture.Save(filePath)

def main ():
    
    snapshots = sc.doc.Snapshots.Names
    namedviews = sc.doc.NamedViews
    
    view_count = 0

    PIXwidth = rs.GetInteger("Width [px] = ",1600)
    PIXheight = rs.GetInteger("Height [px] = ",900)
    
    folder = rs.BrowseForFolder(message="Select destination folder") 

    for view in namedviews:
    
        namedviews.Restore(view_count,sc.doc.Views.ActiveView.ActiveViewport)
        view_count += 1
        for snap in snapshots:
            imagename = (str(snap) + "_" + view.Name + ".jpeg")
            imagepath = folder + "\\" + imagename
            Rhino.RhinoApp.RunScript("-_SnapShots _Restore \"" + snap + "\" _Enter _Enter", False)
            Capture (imagepath,PIXwidth,PIXheight)
            
    rs.MessageBox("All images were added to " + folder,0,"Congrats")

if( __name__ == "__main__" ):
    main()