I’m using python’s rs.command() in Grasshopper to automate some viewCaptureToFile exports. I seem to have everything setup properly, and Rhino’s Command line gets all the way to
Save file name ( Unit=inches Width=800 Height=600 Dpi=300 LockAspectRatio=No DrawGrid=No DrawWorldAxes=No DrawCPlaneAxes=No TransparentBackground=No NumberOfPasses=500 Autoname=Test Browse ): C:\Image.jpg
and does a carriage return but there’s no “File successfully saved…” and the image is not saved. If I manually run the command and copy/paste the same “C:\Image.jpg” + Enter, I do get a confirmation and image saved.
Is there some special way to close out the -viewCaptureToFile command that I’m missing? Here’s the code (sorry - the formatting goes wonky when I paste here, but everything after “if Activate” is indented):
import rhinoscriptsyntax as rs
#wait for bool
if Activate:
folder=str(Directory)
desc=Description
#view size
vWidth=800 ; vHeight=600
#command option string
opts=" _Width="+str(vWidth)+" _Height="+str(vHeight)+" _DrawGrid=_No "
opts+="_DrawWorldAxes=_No _DrawCPlaneAxes=_No _TransparentBackground=_No _Autoname="+"Test Test "
#Run Rhino Command
rs.Command("_-ViewCaptureToFile " +opts +desc)
PS: To format code blocks on Discourse forums (and other Markdown-compatible editors), enclose them in triple-backquotes (or select the block of code and click on the “Preformatted text” button):
The command SEEMS to succeed (it doesn’t hang as I would expect from a missing “Enter”). The Command line returns to normal and the GH Python component shows no error, but no image is exported:
I am actually not saving to C: root, just put that in there for the sake of this public post.
I have added the double quotes to my path without success
When I copy/paste your code (with your file path) I get a similar faux-success. No error or anything, just return to the Command line. If I replace your path with mine I still don’t get any image saved.
So - just to be clear, I’m using this code with no success:
I also get that behavior when I try to save to C:\Image.jpg from unelevated Rhino. Running Rhino as administrator successfully saves to C:\Image.jpg. Can you try that?
If running Rhino as admin solves your issue, you should be able to save your image with an unelevated Rhino as well by giving write permissions to your user for the folder H:\TEST_Delete\.
(Note that if H:\ is a shared drive, there is a chance that the local Administrators group in Windows does not have write permission to that location. In that case running Rhino as admin still won’t solve your issue, but giving write permissions to the folder for the user running Rhino will.)
Also, your path is still not properly escaping backslashes: the string in Python needs to be '"H:\\TEST_Delete\\Image space.jpg"'.
Thanks again for your help with this; I’m SO CLOSE!!
Running Rhino as admin has no effect.
I’ve adapted the code slightly so the path is concatenated outside python to add “”.
Running the script still doesn’t export an image, but copy/pasting the exact same path (from command history) and running -ViewportCaptureToFile manually works perfectly (and doesn’t require pressing enter manually, btw):