Login  Register

Re: Possible to call a javascript script or function (w/ arguments) from a macro?

Posted by lechristophe on Apr 07, 2014; 11:18am
URL: http://imagej.273.s1.nabble.com/Possible-to-call-a-javascript-script-or-function-w-arguments-from-a-macro-tp5006888p5007228.html

Hi Wayne and all the ImageJers,

The runMacro(path, argument) command works fine to call a javascript via
its path from a macro. I'm now trying to do the same from a javascript,
i.e. calling a javascript (as a file with its path) from a javascript.

I used the following method which works with a js file on a Mac (OSX 10.9,
Java 1.6) :
IJ.runMacroFile(path, argument);

but on a PC (XP, Java 1.6), the argument isn't passed to the second
javascript and I get an error about the string litteral not being
terminated (in french, so I'm not sure about my translation).

What do I do wrong? Is there a better way to call a javascript as a file
from another javascript properly?

Thanks for your help,

Christophe


2014-03-13 13:31 GMT+01:00 Christophe Leterrier <
[hidden email]>:

> Thanks Wayne, that is exactly what I was looking for!
>
> Cheers,
>
> Christophe
>
>
> 2014-03-13 4:32 GMT+01:00 Rasband, Wayne (NIH/NIMH) [E] <
> [hidden email]>:
>
> On Mar 12, 2014, at 4:36 PM, Christophe Leterrier wrote:
>>
>> > Hi,
>> >
>> > I'd like to know if it is possible to call some javascript from a macro
>> in
>> > ImageJ. What I want to do is call the javascript, passing some
>> arguments to
>> > it (like a filepath), let it run, and return to the macro for further
>> > processing. How should I proceed ?
>>
>> You can call a JavaScript file and pass it an argument using the
>> runMacro(path,arg) macro function. For example, the macro
>>
>>      rtn = runMacro("test.js", "string argument");
>>      print("return="+rtn);
>>
>> outputs
>>
>>     arg=string argument
>>     return=this is the return value
>>
>> when the file "test.js" (assumed to be in the Image/macros folder)
>> contains
>>
>>     print("arg="+getArgument());
>>     "this is the return value";
>>
>> The JavaScript code retrieves the argument by calling getArgument() and
>> the value of the last expression evaluated ("this is the return value") is
>> returned to the calling macro.
>>
>> -wayne
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html