RE: Save view-port in local path in grasshopper using a different display mode

Hi Nathan,

Thanks for you comment. I tried to do what you suggested but have a weird problem.
What I did is to set target display mode and apply this mode to current viewport.
and then save the view and re-change display mode to original mode.
But, the problem is that generated image is still under original display mode. I think when running the code, generating image takes some time and the display mode is changed fast, so capturetobitmap couldn’t pick the target display mode.
I tried to put some sleep but didn’t work.

Could you give me some advice here?
Thanks!

import System
import Rhino
import scriptcontext as sc
import rhinoscriptsyntax as rs

view = sc.doc.Views.ActiveView
target_display_mode = Rhino.Display.DisplayModeDescription.FindByName("WireFrame")
view.ActiveViewport.DisplayMode = target_display_mode

if view:
    view_capture = Rhino.Display.ViewCapture()
    view_capture.Width = view.ActiveViewport.Size.Width
    view_capture.Height = view.ActiveViewport.Size.Height
    view_capture.ScaleScreenItems = False
    view_capture.DrawAxes = False
    view_capture.DrawGrid = False
    view_capture.DrawGridAxes = False
    view_capture.TransparentBackground = False
    bitmap = view_capture.CaptureToBitmap(view)
    if bitmap:
        path = 'C:/Users/Lei/Desktop/temp/'
        folder = System.Environment.SpecialFolder.Desktop
        filename = System.IO.Path.Combine(path, "SampleViewCaptureToFile.jpg")
        bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg)
        
view = sc.doc.Views.ActiveView
original_display_mode = Rhino.Display.DisplayModeDescription.FindByName("Shaded")
view.ActiveViewport.DisplayMode = original_display_mode

@time2605

Try adding

sc.doc.Views.Redraw()

right after you change the display mode the first time.

p.s. I made the post public, since this is something we can handle in public.

Hi Nathan,

I tried to add the line you mentioned, but it doesn’t work actually… it still saves original display mode, not target one.

The following script should work:

import System
import Rhino
import scriptcontext as sc

view = sc.doc.Views.ActiveView
target_display_mode = Rhino.Display.DisplayModeDescription.FindByName("Wireframe")

if view:
    bitmap = view.CaptureToBitmap(target_display_mode)
    if bitmap:
        path = '/Users/nathan/Desktop/'
        folder = System.Environment.SpecialFolder.Desktop
        filename = System.IO.Path.Combine(path, "SampleViewCaptureToFile.jpg")
        bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg)