Transparent Background? -ViewCaptureToFile

Hello, I am working on a python script that is supposed to make a image for the current view, then hide the current layer, show the next layer and repeat. I was having difficulty with the Rhino.Command(-_Print) and had read that it had known bugs, so the only resources I could find were for the Rhino.Command(-_ViewCaptureToFile). The script seems to be working as intended, the view capture file is accepting my naming convention and going into the right path, but the background is grey and I can’t seem to get the command to accept an input that would change its value. Does anyone know how I can implement Transparent backgrounds, or an alternative method of saving my images to a folder for printing?

The current code I am using for the ViewCaptureToFile is:
“rs.Command(’-_ViewCaptureToFile ‘+chr(34)+Result+i+’.png’+chr(34)+’ _Enter’)”

Thank you to everyone in advance!!

Hi @cad7,

Here is a simple, sample script that allows you to to control transparency.

SampleViewCaptureToFile.py

Does this help?

– Dale

Hello, Thank you for providing the sample script. I had seen this previously but overlooked the “.TransparentBackground” area, but I had abandoned this script as a reference because I was unable to get it to run from even pasting it into a blank script. I believe this script is a great example for what I am trying to do but I am unaware of how to extract the line I need and get it working when the example itself is not working.

The error I receive when trying to run this code as is:
" Message: attribute ‘ViewCapture’ of ‘namespace#’ object is read-only

Traceback:
line 10, in SampleViewCaptureToFile, “C:\Users\nate\AppData\Local\Temp\TempScript.py”
line 29, in , “C:\Users\nate\AppData\Local\Temp\TempScript.py”
"

Hi @cad7,

There script runs here in Rhino 6 SR30 without a hitch…

– Dale

I am working in Rhino 5. Is there a way to set the .TransparentBackground to True without the ViewCapture() command that is holding it up? The issue is the view_capture = ViewCapture section, I’d like to, if possible, eliminate all the view_capture lines?

Hi @cad7,

I don’t recall if Rhino 5 supported transparency when capturing a view (probably not).

– Dale

The option exists in the form of a checkbox when doing ViewCaptureToFile and it works, the issue is getting that to be the default or setting it to True from the script…

The RhinoCommon ViewCapture class was added in 6.0

Hi @cad7,

In Rhino 5, the ViewCaptureToFile does not display a dialog box, other than to prompt you for the name of the file to save.

Anyway, give this sample a shot:

import rhinoscriptsyntax as rs
import System

folder = System.Environment.SpecialFolder.Desktop
path = System.Environment.GetFolderPath(folder)

filename = System.IO.Path.Combine(path, 'Test.png');
filename = '"' + filename + '"'

cmd = '_-ViewCaptureToFile ' + filename + ' '
cmd = cmd + '_TransparentBackground=_Yes _Enter'

rs.Command(cmd, True)

– Dale

Thank you! This is exactly the example I was looking for! I was able to get it working without prompt using the code rs.Command('-_ViewCaptureToFile '+chr(34)+Result+i+'.png'+chr(34)+ ' _TransparentBackground=_Yes'' _Enter') in place of my original. I really appreciate the help!!!