Change the colormode of ViewCapturetoFile

Is there a way to change the colormode of command “ViewCapturetoFile” ?
So that I can choose to output a BlackAndWhite, PrintColor or DisplayColor?

Colormode setting is currently unaccessible through adding - in front of the command.
But I think it is a manipulable setting.

https://developer.rhino3d.com/api/rhinocommon/rhino.display.viewcapturesettings.colormode

If it has to be achieved through running a C# script, I am happy to do that!

Sounds like you’re after the OutputColor property.

https://developer.rhino3d.com/api/rhinocommon/rhino.display.viewcapturesettings/outputcolor

hi Travis, yes. I would really appreciate if there is a sample code that achieves similar function that I can reference to… I have done some Python but don’t have too much experience with C#

Where is your script? These API’s work with both languages.

Hi Travis, thanks for the quick response.
I don’t have a script started yet for this effort. In fact, I am not sure how to start.

I have seen the [rhino.display.viewcapturesettings/outputcolor] you shared with me before.
But my experience outside Rhinoscriptsyntax is almost none and it’s not too helpful for me.

Would you please kindly point me to something that I can take a look at.
Thanks again.

I see, sorry I thought you were suggesting that you might have had a start to an existing python script.

You can find scripting examples here for Python and C#. I would highly suggest using the examples provided to help get you started with scripting.

More specifically here’s a basic example of capturing a view to a black and white image file.

import System
from System.Drawing import Imaging
from System.Environment import GetFolderPath, SpecialFolder
import Rhino
import Rhino.Display as display

def capture_black_and_white_view():
    view = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView
    if view is None:
        return Rhino.Commands.Result.Cancel

    vcs = display.ViewCaptureSettings(view, view.Size, 72)
    vcs.OutputColor = display.ViewCaptureSettings.ColorMode.BlackAndWhite
    vcs.RasterMode = True
    vcs.SetModelScaleToFit(False)

    bitmap = display.ViewCapture.CaptureToBitmap(vcs)
    if bitmap is None:
        return Rhino.Commands.Result.Cancel

    desktop_path = GetFolderPath(SpecialFolder.Desktop)
    output_file_path = System.IO.Path.Combine(desktop_path, "ViewCapture_BW.png")

    bitmap.Save(output_file_path, Imaging.ImageFormat.Png)
    bitmap.Dispose()


    return Rhino.Commands.Result.Success

capture_black_and_white_view()

I’ve also created a ticket to add the Output Color option to the command.

https://mcneel.myjetbrains.com/youtrack/issue/RH-85006/ViewCaptureToFile-Add-OutputColor-support

Also note that you can use the Print command and save as a black and white image with more options than what the ViewCaptureToFile command offers but not as easy to create macros with.

2 Likes

I really appreciate that!
Quick question: if I run this code, would it affect the color output setting of my regular rhino command “ViewCapturetoFile” ?

No, this isn’t connected to the command in any way.

1 Like

Hi Travis, do you happen to know how I can get the script to capture the color and lineweight of printdisplay?

Have you tried adjusting the Output Color? It can be set to Display, Print, or Black and White.

https://developer.rhino3d.com/api/rhinocommon/rhino.display.viewcapturesettings.colormode