I tried to write the following script for opening all files from one folder and saving them in an other one.
However, it’s not working and I can’t figure out what I’m doing wrong. Im working with Version 5.3.2
Someone here that can point me to what exactly is wrong with this script?
import rhinoscriptsyntax as rs
import os.path
def BatchSaveAs():
folder = rs.BrowseForFolder("/Users/jehrenstein/Desktop/TEST/stp")
if folder: print folder
saveFolder = rs.BrowseForFolder("/Users/jehrenstein/Desktop/TEST/obj")
if saveFolder: print saveFolder
for filename in os.listdir(folder):
if filename.endswith(".stp"):
fullpath = os.path.join(folder,filename).lower()
rs.EnableRedraw(False)
rs.DocumentModified(False)
rs.Command("_-New _None",False)
rs.Command('_-Open {} _Enter'.format(fullpath))
comm="_-Export"
rs.Command(comm + chr(34) + saveFolder + "/" + filename + chr(34) + ".obj" + "_Enter")
rs.DocumentModified(False)
rs.Command("_-New _None",False)
rs.EnableRedraw(True)
BatchSaveAs()
I just started with Rhino and Python, so I’m really thankful for any help.
@RIL I’m with emilio, but thanks for your input Rolf! @emilio I added “SelAll” to the commands @jeff_hammond do I even need it, or can I just use the path as string?
import rhinoscriptsyntax as rs
import os.path
def BatchSaveAs():
folder = "/Users/jehrenstein/Desktop/TEST/stp"
if folder: print folder
saveFolder = "/Users/jehrenstein/Desktop/TEST/obj"
if saveFolder: print saveFolder
for filename in os.listdir(folder):
if filename.endswith(".stp"):
fullpath = os.path.join(folder,filename).lower()
rs.EnableRedraw(False)
rs.DocumentModified(False)
rs.Command("_-New _None",False)
rs.Command('_-Open {} _Enter'.format(fullpath))
rs.Command("_-SelAll")
comm="_-Export"
rs.Command(comm + chr(34) + saveFolder + "/" + filename + chr(34) + ".obj" + "_Enter")
rs.DocumentModified(False)
rs.Command("_-New _None",False)
rs.EnableRedraw(True)
BatchSaveAs()
that works… it’s using -Import instead of -Open because i don’t think Open is scriptable on Mac but Import is.
so, open a blank file in Rhino and run the script from there… it just imports then deletes when finished instead of opening a new file then closing it.
(oh… the Users/jeff path won’t work… switch it back to your user name )
I’m trying to do something similar on a windows computer.
I successfully cycle through the script but when it comes to the Export (I’ve also tried Save), it prompts me to save the filename as opposed to using the existing filename.