Hi,
I have a script (javascript) that calls functions in another script using load(path). It works fine in Fiji thanks to Johannes' work (see http://imagej.1557.x6.nabble.com/Javascript-in-Fiji-does-not-work-anymore-td5008314.html ). I have now made a toolset to launch these various scripts using the runMacro(path) command. So what happens is that the Action Tool calls the script#1 using runMacro(path1), and the script#1 calls functions in script#2 using load(path2). However when I do this, I get an error (that does not happen when launching script#1 directly: ReferenceError: "load" is not defined (<Unknown source>#35) in <Unknown source> at line number 35 Anyone knows what happens here, and knows how to work around/correct this? Thanks, Christophe -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
2014-10-30 16:48 GMT+01:00 Christophe Leterrier <
[hidden email]>: > Hi, > > I have a script (javascript) that calls functions in another script using > load(path). It works fine in Fiji thanks to Johannes' work (see > http://imagej.1557.x6.nabble.com/Javascript-in-Fiji-does-not-work-anymore-td5008314.html > ). > > I have now made a toolset to launch these various scripts using the > runMacro(path) command. So what happens is that the Action Tool calls the > script#1 using runMacro(path1), and the script#1 calls functions in > script#2 using load(path2). However when I do this, I get an error (that > does not happen when launching script#1 directly: > > ReferenceError: "load" is not defined (<Unknown source>#35) in <Unknown > source> at line number 35 > > Anyone knows what happens here, and knows how to work around/correct this? > > Thanks, > > Christophe > To complete my post, I tried adding a custom load function (provided by Johannes here: http://imagej.1557.x6.nabble.com/Newbie-JavaScript-question-td4626432.html) to my script#2: function customload(path) { importClass(Packages.org.mozilla.javascript.Context); importClass(Packages.java.io.FileReader); var cx = Context.getCurrentContext(); cx.evaluateReader(this, new FileReader(path), path, 1, null); } and now the error is: TypeError: Cannot call method "evaluateReader" of null (<Unknown source>#45) in <Unknown source> at line number 45 Which would point at a problem with the context retrieval when the script is not called directly, but from somewhere else (either a script or a macro). I tried to understand what the Context class is but this is way over my knowledge... Would someone indicate a fix that would allow me to run this? It is important for me because it would allow me to group my scripts into a Toolset before giving them to other users. Thanks for the help, Christophe -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
I'll answer my own question, as my post was deemed too esoteric for the IJ
mailing list, and until a Fiji guy has a look at the load() issue (if not, I can add a warning to this part of the wiki: http://fiji.sc/JavaScript_Scripting#Using_other_.js_files_as_libraries) . After banging my head trying all sort of convoluted work around, I did what everyones struggling with script/macro programming should do: use the Macro Recorder. It showed me that replacing runMacro(path_to_script_1) by a simple run("script 1") solved the problem, as my scripts (and thus script#1) live in the plugin folder and have an underscore un their names. Christophe 2014-10-31 11:14 GMT+01:00 Christophe Leterrier < [hidden email]>: > 2014-10-30 16:48 GMT+01:00 Christophe Leterrier < > [hidden email]>: > >> Hi, >> >> I have a script (javascript) that calls functions in another script using >> load(path). It works fine in Fiji thanks to Johannes' work (see >> http://imagej.1557.x6.nabble.com/Javascript-in-Fiji-does-not-work-anymore-td5008314.html >> ). >> >> I have now made a toolset to launch these various scripts using the >> runMacro(path) command. So what happens is that the Action Tool calls the >> script#1 using runMacro(path1), and the script#1 calls functions in >> script#2 using load(path2). However when I do this, I get an error (that >> does not happen when launching script#1 directly: >> >> ReferenceError: "load" is not defined (<Unknown source>#35) in <Unknown >> source> at line number 35 >> >> Anyone knows what happens here, and knows how to work around/correct this? >> >> Thanks, >> >> Christophe >> > > To complete my post, I tried adding a custom load function (provided by > Johannes here: > http://imagej.1557.x6.nabble.com/Newbie-JavaScript-question-td4626432.html) > to my script#2: > > function customload(path) { > importClass(Packages.org.mozilla.javascript.Context); > importClass(Packages.java.io.FileReader); > var cx = Context.getCurrentContext(); > cx.evaluateReader(this, new FileReader(path), path, 1, > null); > } > > and now the error is: > TypeError: Cannot call method "evaluateReader" of null (<Unknown > source>#45) in <Unknown source> at line number 45 > > Which would point at a problem with the context retrieval when the script > is not called directly, but from somewhere else (either a script or a > macro). I tried to understand what the Context class is but this is way > over my knowledge... > > Would someone indicate a fix that would allow me to run this? It is > important for me because it would allow me to group my scripts into a > Toolset before giving them to other users. > > Thanks for the help, > > Christophe > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On Oct 30, 2014, at 11:48 AM, Christophe Leterrier <[hidden email]> wrote:
> > Hi, > > I have a script (javascript) that calls functions in another script using > load(path). It works fine in Fiji thanks to Johannes' work (see > http://imagej.1557.x6.nabble.com/Javascript-in-Fiji-does-not-work-anymore-td5008314.html > ). > > I have now made a toolset to launch these various scripts using the > runMacro(path) command. So what happens is that the Action Tool calls the > script#1 using runMacro(path1), and the script#1 calls functions in > script#2 using load(path2). However when I do this, I get an error (that > does not happen when launching script#1 directly: > > ReferenceError: "load" is not defined (<Unknown source>#35) in <Unknown > source> at line number 35 > > Anyone knows what happens here, and knows how to work around/correct this? Upgrade to the latest ImageJ daily build (1.48k6). The JavaScript interpreter in earlier versions does not support the load(path) function. -wayne -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |