sketchpath in the settings()

I try to catch the sketchpath in the settings() but i cannot use the sketchPath() method. I try few stuff but it's too much hard for me. bellow my try !

void settings() {
  String folder = null ;
  String jarPath = PApplet.class.getProtectionDomain().getCodeSource().getLocation().getPath();
  if (jarPath.contains("Contents/Java/")) {
    String appPath = jarPath.substring(0, jarPath.indexOf(".app") + 4);
    File containingFolder = new File(appPath).getParentFile();
    folder = containingFolder.getAbsolutePath();
  }
  println(jarPath) ;
  println(folder) ;

  File currentDirectory = new File(new File(".").getAbsolutePath());
  println(currentDirectory) ;
  println(currentDirectory.getAbsolutePath()) ;

}

void setup() {
  println(sketchPath()) ;
}

Answers

  • edited September 2015 Answer ✓

    Well, I've told ya in your previous thread that the source code itself needs fix: :-@
    http://forum.processing.org/two/discussion/12568/choice-where-to-display-the-fullscreen-from-external-file

    Processing 3, besides bringing lotsa bugs and not any worthy feature, has arrogantly decided to lock everything up so we can't fix the library by ourselves either! X(

    Contrary to what we would expected from sketchPath(), it can't find out sketch's path whatsoever!
    Actually it is Processing's IDE (PDE) which passes it to the running sketch via "--sketch-path=" arg! (:|

    Problem is that sketchPath variable (which is now private to make matters worse), only receives "--sketch-path=" just after settings() call is finished! @-)

    In short, when code is inside settings(), it is oblivious to the "true" sketch's path! 3:-O

    Most we can do is export the sketch via CTRL + SHIFT + E.
    In which case sketchPath(), dataPath(), sketchFile() & dataFile() finally work inside settings(): :-\"

    // forum.processing.org/two/discussion/12572/sketchpath-in-the-settings
    // 2015-Sep-18
    
    String AppSketchPath, AppDataPath;
    
    void settings() {
      size(800, 200, JAVA2D);
      noLoop();
      AppSketchPath = sketchPath();
      AppDataPath = dataPath("");
    }
    
    void setup() {
      getSurface().setTitle(AppDataPath);
      String[] paths = { AppSketchPath, AppDataPath };
      saveStrings(AppDataPath + "/Paths.txt", paths);
    }
    
  • edited September 2015

    Like I say that's don't work ... maybe only on OSX :( Capture d’écran 2015-09-19 à 19.04.34

  • edited September 2015

    Have you exported the application and double-clicked on it to run it? :-/
    It works in Windows both by double-clicking it and from the console. :(|)

  • Oops, that's work. Sorry, i'm not conforatable with english, I haven't understand that I must creata an app to check. Thank you very very much. Now, I Must work around that, to create a path for my project !

  • If I understand is not possible to find the path in the settings() except with the export app. If I want find the path with the sketch I write a method with JAVA ?

  • edited September 2015

    Again, I've already answered that in your previous post:
    http://forum.processing.org/two/discussion/12568/choice-where-to-display-the-fullscreen-from-external-file

    That's why it's very bad opening new forum threads for the same subject! Creates fragmentation! :-@

    Class PApplet itself needs to be fixed in order for sketchPath (and others like args[]) to be correctly initialized w/ the actual running code's path inside settings()! [-(

    You can ask "them" to make that needed correction here:
    https://GitHub.com/processing/processing/issues

    But watch out: They don't like such "implementation detail" requests and they "bite" hard! >:)

Sign In or Register to comment.