Return value of rs.command(-_ViewCaptureToFile)

In on of my scripts, I have the line

success = rs.command( "-_ViewCaptureToFile 'path/file.png' _Enter" )
(other args obmitted for brevity)

This worked fine in R5, and the call returned 1.

Running the same script in R6 returns False, although the PNG image is successfully created. Is there any reason why I’m getting a ‘False’ return value now?

Thank you

Hi axa,

I can´t seem to be able to reproduce your problem. The only error I could find was the capital C in command:

success = rs.Command( "-_ViewCaptureToFile 'path/file.png' _Enter" )

returns ´True´. Can you please provide a bit more context?

You might also consider calling the RhinoCommon method directly, as seen here: A way to screencapture and send to print with one button?

1 Like

So I think I shot my self in the foot here by not properly enclosing the file path (which has spaces in it) in double inverted commas. Also, it seems the file name came directly after -ViewCaptureToFile in R5, but needs to be the last argument in R6. This works:

    # Warning: Width and Height options persist when the command is run in scripting mode
    view_size = rs.ViewSize()

    common_options = " _Width={w} _Height={h}".format(w=view_size[0],h=view_size[1])
    common_options += " _Scale={s}".format(s=self.scale)
    common_options += " _DrawGrid=_No _DrawWorldAxes=_No _DrawCPlaneAxes=_No"

    if rs.ExeVersion() < 6:
        # Rhino 5 had a bug with transparent backgrounds
        transp = '_No'
        cmd  = '-_ViewCaptureToFile "{f}"'.format(f=file_name)
        cmd += common_options
        cmd += " _TransparentBackground={t}".format(t=transp)
        cmd += " _Enter"
        transp = '_Yes'
        cmd  = '-_ViewCaptureToFile'
        cmd += common_options
        cmd += " _TransparentBackground={t}".format(t=transp)
        #cmd += " _Unit=pixels _LockAspectRatio=_Yes _ScaleDrawing=_No"
        #cmd += " _NumberOfPasses=50"
        cmd += ' "{f}"'.format(f=file_name)
        cmd += " _Enter"

    success = rs.Command(cmd, echo=False)
    if not success:
        print("Error capturing PNG image.")
        return False

Thank you