How to automate screendump creation of folder of sketches?

edited July 2017 in How To...

Hi,

I recently taught a course on Computational Graphic Design, and the students have all handed in their assignments. This leaves me with a folder and several subfolders packed with Processing sketches. To get a visual overview of their assignments, I would like to automate the process of 1) traversing the folder structure, 2) opening all encountered ".pde" files one at a time, 3) run the open sketch, and 4) save the canvas - either directly from within Processing or via any third party software. Being able to do so will save me a lot of time, but I haven't got the slightest clue about how to make this happen. Any input will be highly appreciated. Thanks!

Answers

  • edited June 2017 Answer ✓

    @Stixan -- Interesting teaching question.

    One approach is to discover sketches with a shell script, run each sketch from the command line, however run a modified version that injects a call to saveFrame().

    Traversing the directories

    note that, like Java classes, the only pde files you need to check for are ones with match their folder name exactly -- e.g. for these pdes:

    /Docs/sketches/student1/myGreatSketch/1.pde
    /Docs/sketches/student1/myGreatSketch/another.pde
    /Docs/sketches/student1/myGreatSketch/myGreatSketch.pde
    /Docs/sketches/student1/myGreatSketch/myResources.pde
    

    You should only run:

    /Docs/sketches/student1/myGreatSketch/myGreatSketch.pde
    

    This is not a valid sketch:

    /Docs/sketches/student2/BrokenSketch/1.pde
    /Docs/sketches/student2/BrokenSketch/2.pde
    

    Running from the command line

    Once you have your sketch list and are looping through running them, use the command line interface:

    Like this:

    processing-java --sketch=<name> --run
    

    Adding saveFrame

    Assuming you don't have any sketches with animation, you want to add a call to saveFrame() after the first full draw loop (unless the sketch is written in immediate mode). Here are two ways of doing that

    1. at the beginning of draw() when frameCount==2
    2. via a library registered method using void post(){}

    For the draw() approach, assuming that each sketch has this line:

    void draw(){
    

    ...then you could replace it (in a copy, or dynamically at run time) with this:

    void draw(){
      if(frameCount>1){
        saveFrame();
        exit();
      }
    

    ...however note that this assumes noLoop() is not set and exit() is not manually called after the first frame.

    Alternately you instead add saveFrame() to the end of the draw loop -- but this can't be done reliably with search and replace, you need to either do it manually or parse the code.

    For the library approach, create a simple library which defines a post() method to run immediately after draw. Register the method:

    parent.registerMethod("post", this);
    
    public void post(){
      saveFrame();
      exit();
    }
    

    ...then prepend any sketch you run with a line importing your library:

    import mySaveFrameLibrary;
    

    Adding saveFrame to Immediate mode

    I'm not actually sure if a library with post() works for sketches written in immediately mode (i.e. sketches with no draw() or setup()) -- I think it does. However, if the sketch does not contain "void draw" then it is written in immediate mode, and you can simply append saveFrame(); as the last line (...assuming it doesn't call exit() -- if it does, you need to prepend it above the exit line).


    Related past discussions:


    P.S. Another approach in the future is to require that students end all their static sketches with a call to saveFrame().

  • Wow, thanks @jeremydouglass! Pretty detailed plan of how to attack this problem. I'll look into it, but I have a sneaking suspicion that I might be coming back to kindly ask that you elaborate on a number of the steps.

  • I gave it a shot but didn't manage to get it working. Accepting @jeremydouglass answer though, as I think it is the right way to solve what I initially asked to do. Personally I'm simply lacking the skills required to get it to work.

  • I am not sure if this could help as you need to provide the .java files directly into this sketch as suggested in this post: http://forum.happycoding.io/t/how-to-make-a-processing-showcase/83/2

    @jeremydouglass Is it possible to generate the java file and place it in a gfolder inside the sketch folder? I think it is worth it to implement a demo to do this. However, there are some restrictions to consider when doing something like this.... for example, a sketch calling exit or having calls to noLoop()....

    Kf

Sign In or Register to comment.