Working with Arguments and Loading files upon opening application

edited February 2016 in Questions about Code

Is it still possible to open an exported application in processing through another file that it would then use? Essentially I want to open, say an image file, using "open with"... "myExportedApplication.exe" and it send the file path to load the image to setup for me to preload the image.

These three older links below showed how to do this, but I can't seem to get them to work with the newest version of Processing 3.0.1. My application attempts to load but fails without ever showing anything. I also tried 2.2.1. args[0] does not seem to receive the file path data like these links describe. I tried actually copying the code out of the third link below with no luck.

https://processing.org/discourse/beta/num_1240685119.html

https://forum.processing.org/one/topic/using-an-application-written-in-processing-to-open-up-a-file.html

https://forum.processing.org/two/discussion/6457/how-to-use-arguments-with-an-application-built-with-processing#latest

Berenger's code from above link:

    PImage img;

    void setup() {
      size(800, 400);
      textSize(15);
      if (args.length != 0) {
        img = loadImage(args[0]);
      }
    }

    void draw() {

      text("\n# of args: " + args.length + "\n", 20, 25);
      for (int i = 0 ; i < args.length ; i++) { 
        text(args[i], 20, 75+ i*50);
      }
      if (args.length != 0) {
        image(img, 0, 0);
      }
    }
Tagged:
Sign In or Register to comment.