Posted by
lechristophe on
Oct 31, 2014; 10:14am
URL: http://imagej.273.s1.nabble.com/load-path-does-work-in-javascript-but-not-if-called-from-a-macro-tp5010245p5010262.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