Batch opening of multiple files

I have a list of 50-ish files, each one requires to do small adjustment.
Picking files one-by one from a long list is painful and risking omitting some.
Are you guys having any trick to make Rhino opening consecutively list of files?

Hi Piotr -
I’ve moved this to the Scripting category. If you search, there should be several topics on opening lists of files. The thing that is more important, I suppose, is what adjustment you need to make.
-wim

Adjustment can vary and may not apply to all files, but all of them needs to be checked.

Opening a list of files consecutively is not that hard.
However, if you want to manually do things within that file, there needs to be a way to know you are finished and track what file to open next…

How is that list composed currently?

What I can think of is tracking when the file is last changed maybe?
So you can ensure what files have been touched recently and what not…

Looking at the update date is the way to go, for sure, but having MANY files requires constant scrolling down the list which is anything but convenient.

Are these files located in 1 folder, or spread over many folders?

Yes, they are resting in the same folder.

Could you not:

  • sort them by date to see the earliest edits.
  • Select a batch of 10 and open them
  • Do the edits, save and close.

Rinse and repeat

?

I’m not sayin this cannot be automated buy I’m looking for a simple solution that is already at hand.
Especially since the edits that need to be done are not something you can/want to automate right?

That is certainly the way to do it. I was hoping for something smarter :wink: that takes away some responsibility after day of hard work.

I see, but as you are manually editing them, it is not obvious to make it clear when the next file should be opened.
Would you want to run this as a single session on all files in one go?
I can come up with ways probably, but before that is somewhat robustly coded, you are probably done the hard way.

Is this something you need to do often, or just a one time thing?

I have a project where I need to do it once in a while, let’s say a month intervals.
I have imagined a process where I can mark all files in a folder and Rhino opens first one then, after closing command (eg. ctrl+W) opens another one and so on (kind of Photoshop style).

How about this:
open_one_by_one.py (850 Bytes)

Note that there is no escape and the time between closing one file and opening another is IMO annoyingly long. But for now I see no way around it.

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
import subprocess
import os


def run_on_folder():
    
    folder = rs.BrowseForFolder('get folder to open 3dm one by one')
    if not folder:
        return

    all_files = [os.path.join(folder, file) for file in os.listdir(folder) if os.path.isfile(os.path.join(folder, file))]

    rhino_files = [file for file in all_files if os.path.splitext(os.path.join(folder, file))[1] == '.3dm']
    
    ui = rs.MessageBox('Start opening {} rhinofiles\none by one?'.format(len(rhino_files)), buttons = 4)
    if ui != 6:
        return
    
    for rhino_file in rhino_files:
        filestr = '"{}"'.format(rhino_file)
        print subprocess.call(filestr, shell=True)
        
    Rhino.RhinoApp.Exit()

if __name__ == '__main__':

    run_on_folder()

Thanks! I will give it a try and let you know how it works.

Maybe a solution where all the file names are written to an index text file in the same folder? a simple command could/would read the file contents, open the first (or last) file name in the list, and then write the rest of the other file names back to the original index file? You could trigger the process with an “openNext” command or something. Interesting problem to solve…

Hi Willem
Today is the day when I needed it to work to edit consecutively 111 files.
I have opened new session of Rhino and loaded your script. It asked me to load all files and crashed immediately.
I’m back to manual loading the files. Sigh.

Hi Piotr,

One way to maybe sort of fix this is to create a pauze between opening files.
It can easily be tested by adding a line
rs.Sleep(5000) # wait 5 seconds


    for rhino_file in rhino_files:
        filestr = '"{}"'.format(rhino_file)
        print subprocess.call(filestr, shell=True)
        rs.Sleep(5000) # wait 5 seconds

However I think 111 files open is better avoided and a smarter tool be build to eg open only a new instance if no more than day 10 others are open…

Unfortunately I am not familiar with coding so I can’t interpret it.
My goal was not to open huge number of Rhino instances but to auto-open B file when A is saved, then C when B is saved (question being what command would make the file closed and another open).

Hmmm I see,

I’m afraid I don’t have a quick fix for that.

bummer
-Willem

Don’t worry, thanks for trying.
P