I will do so tomorrow by describing the problem in more detail and asking my colleagues exactly which versions of OS and Processing they have.
The only thing that changed from the original project I uploaded was in the Main.pde file, so I will make sure to document the changes in the solution thoroughly.
Itâs expecting the name of the class that extends PApplet and thatâs what this.getClass().getSimpleName() does. If the name of your class is âTestWindowâ and you use
that will work too (on a mac, not tested on other platforms).
Actually you can get by with only this:
PApplet.runSketch(new String[]{""},this);
In summary, using sketchPath() in a PApplet returns only a forwardslash on my system and is worthless. Iâm sticking with my last snippet unless someone has a compelling reason to change.
If you want to confirm my findings here is a test app that you may run:
Indeed, that was a very old example which I had forgotten to include an '=' character, which is required for the runSketch()'s switch/case block parser:
So this is the fixed line: final String[] switches = { ARGS_SKETCH_FOLDER + '=' + sketchPath(), "" };
Your output on Windows is different from a Mac; there appears to be platform differences! Does my demo run with an empty string, ie do you see the âTest Windowâ? Hereâs what I see on Windows 11 with an empty string in the array:
We do not seem to be on the same page in this discussion.
Each OS seems to have its nuances and I am getting lost in the quagmire.
Curiosity is the beginning of all wisdom .â - Quote by Françoise Sagan.
This is the objective I have been working towards:
This code launches a new TestWindow instance and correctly passes the ARGS_SKETCH_FOLDER argument to ensure that sketchPath() and dataPath() resolve properly within the new PApplet.
This code achieves that objective on Windows 10 and Processing 4.4.10 :
// Main sketch
TestWindow testWindow;
void setup() {
// The argument array MUST contain the equals sign to work:
final String[] switches = { ARGS_SKETCH_FOLDER + "=" + sketchPath(), "" };
//final String[] switches = { "" };
println("--- Main Sketch ---");
println("Main sketchPath:");
println(sketchPath());
println("Arguments Passed:");
printArray(switches);
// Launch the PApplet instance
runSketch(switches, testWindow = new TestWindow());
}
void draw() {
exit();
}
// Separate PApplet class
class TestWindow extends PApplet {
void settings() {
size(200, 200);
}
void setup() {
background(100);
println("\n--- TestWindow PApplet ---");
// 'testWindow' (lowercase) refers to the launched instance:
println("testWindow sketchPath: ");
println(sketchPath());
println("testWindow dataPath:");
println(dataPath(""));
}
void draw() {}
}
I also passed a global variable in earlier examples.
This was certainly an engaging topic, and all good things must come to an end⌠my participation will have to end here.
I concede that { ARGS_SKETCH_FOLDER + â=â + sketchPath(), ââ }; is necessary to pass sketchPath() from a Processing app to the PApplet; it also allows loadImage(âmyImg.pngâ) to work correctly on a Mac after doing that. What I canât figure out is how the dataPath(ââ) got passed.
Thanks. I finally figured that out; once youâve got sketchPath() itâs pretty easy to tack on â/dataâ. This thread has been instructive in a number of ways: 1) There are differences in the platforms 2) At least on a Mac, PApplet doesnât know its sketchPath()/dataPath() 3) There is a way to pass sketchPath() in from a base Processing app or alternatively use the full path to the data folder for a call such as loadImage() which depends on it.