I’ve found a few other threads to touch on the topic of scripting w/ -ViewCaptureToFile, but none of them seem to specifically address the problem I’m having.
Problem: Script finishes running and successfully changes the active view and changes the display mode, however, it fails to actually output a file.
Any help/suggestions would be greatly appreciated. Thanks!
it looks like you are missing a space in your last line between filename and _Width. Also take care at the end of the last line there are too many spaces before the _Enter.
btw. you might consider to put quotes around the filename so rhino’s commandline does not interpret the spaces as Enter like below:
Thank you for the reply. I tried cleaning up the code and inserting the spaces as you suggested. chr(34) seems to be ‘double quote’ and chr(32) ‘space’. The command is still running all the way through, and when I type it manually the width, height, and scale are indeed all changed. It doesn’t seem to be passing the file path through, as there is no file output. Any other thoughts?
Thanks!
import Rhino
import sys
I really appreciate your help. I also appreciate your notes about why you did certain things.
This little tool will likely save myself and co-workers time, but I’m primarily working on it as a means of learning python.
Thanks for helping me along the way!
import Rhino
import rhinoscriptsyntax as rs
import sys
import time
#import time
fileLocation = "C:\\Users\\norwoodw\\Desktop\\ViewCaptureTest\\"
Name = "2017_0807-TestCapture"
fileExtension = ".png"
fileName = chr(34) + fileLocation + Name + fileExtension + chr(34)
cmd = " _Width 1600 _Height 900 _Scale 4 _TransparentBackgroud _Yes _Enter"
views = rs.NamedViews()
if views:
for view in views:
fileName = chr(34) + fileLocation + Name + view + fileExtension + chr(34)
rs.RestoreNamedView (view)
rs.Command("-SetDisplayMode " + "PW_Architectural")
rs.Command("-ViewCaptureToFile " + fileName + cmd)
print ("Successfully captured view "+(view)+"!")
time.sleep(.5)
else:
print ("There are no named views detected.")
print("Successfully caputered all named views!")
In many programming languages, the backslash character in a string denotes a string literal. Thus, if you want to use a backslash in a string, and not as a string literal, then you need to specify 2 backslashes. For example:
# BAD
path = "C:\Users\norwoodw\Desktop\ViewCaptureTest\"
# GOOD
path = "C:\\Users\\norwoodw\\Desktop\\ViewCaptureTest\\"
Also, when passing strings to the Rhino command line, if the string contains spaces, then the whole string should be surrounded by double-quote characters. This is because Rhino interprets spaces as an key character. For example:
# BAD
path = "C:\\Users\\norwoodw\\Desktop\\View Capture Test\\"
# GOOD
path = chr(34) + "C:\\Users\\norwoodw\\Desktop\\View Capture Test\\" + chr(34)
where the ASCII character 34 is a double-quote character.
Note, if you do this a lot, it can be useful to have a utility function that does this for you. For example: