[ImageJ-devel] Scripting examples

Brian Northan bnorthan at gmail.com
Wed Feb 19 11:22:36 CST 2014


Hi Curtis, Johannes and list

The scripting is working well.

One quick question.  To run a command and retrieve the output I basically
have this

--snip--
# @CommandService command

module=command.run("somecommand").get();
output=module.getOutputs().get("output");

(or)
output = module.getOutputs().values().toArray()[0];
--snap--

I'm wondering if there is a more concise way to run the command and get the
output?? Something more like this....

output=command.run("somecommand");

Basically a way to run the command, have it automatically block, and return
the output(s) (if they exist).  I could write a wrapper but first I want to
make sure I know what all ready exists.


On Tue, Feb 18, 2014 at 4:14 PM, Brian Northan <bnorthan at gmail.com> wrote:

> Thanks very much Johannes and Curtis
>
> Johannes' code snippet works perfectly.  That's exactly what I needed to
> know.  How to access the services from a script.  Now that I know how to do
> that I can try some more complicated stuff (use the datasetservice and
> commandservice to open images and perform operations).  I will let you know
> if any questions come up.  Please let me know any additional information or
> tips that will be helpful.
>
> Thanks again
>
> Brian
>
>
> On Tue, Feb 18, 2014 at 2:26 PM, Curtis Rueden <ctrueden at wisc.edu> wrote:
>
>> Hi Brian,
>>
>> I am out of the office today, and will reply in more detail later, but
>> just wanted to quickly add: the example Johannes wrote should work with the
>> current master branch as well as the recent 2.0.0-beta-7.7 release.
>> Specifically, it will work if you "Run Script" since the parameter parsing
>> mechanism etc. is all already in place. It just doesn't work from the
>> Script Editor yet since that tool needs some TLC still. As Johannes says, I
>> am still actively hacking on scripting support.
>>
>> Also note that you can inject a Context parameter then make a new ImageJ
>> gateway object wrapping it to easily access services the same way the
>> tutorials do. (I forget whether ImageJ gateways are injectable ATM but if
>> not, they will be.)
>>
>> Anyway, please let us know if you are unable to run such scripts.
>>
>> Regards,
>> Curtis
>> On Feb 18, 2014 12:41 PM, "Johannes Schindelin" <
>> Johannes.Schindelin at gmx.de> wrote:
>>
>>> Hi Brian,
>>>
>>> On Tue, 18 Feb 2014, Brian Northan wrote:
>>>
>>> > Now I am trying to understand how one should be accessing ImageJ2
>>> > functionality from the scripts.  In ImageJ1 I use the static functions
>>> in
>>> > the IJ class, IJ.run, IJ.openImage etc.
>>>
>>> Yeah, in IJ2 you have to use a context. The static functions of ImageJ
>>> 1.x
>>> do not allow you to insulate separate processes from each other. That
>>> leads to surprising results, e.g. when you try to put more than one
>>> ImageJ 1.x applet into the same web page: it simply won't work, ever.
>>>
>>> > So far in ImageJ2 I have been writing java applications that start by
>>> > instantiating an ImageJ app and then use that to access services and
>>> run
>>> > commands. Basically following the tutorials.
>>> >
>>> > So how are things intended to work in a script??  Is there a simpler
>>> api
>>> > somewhere like the IJ API??  Or does one still need to use the service
>>> APIs
>>> > in a script??
>>>
>>> This is a work in progress right now, under heavy construction.
>>> Eventually, something like this will work:
>>>
>>> -- snip --
>>> # @StatusService status
>>> # @OUTPUT String greeting
>>>
>>> status.showStatus(1, 2, "In progress...")
>>> status.warn("This is a gentle warning")
>>> status.showStatus(2, 2)
>>>
>>> greeting = "Hello, world!"
>>> -- snap --
>>>
>>> In other words, your input and output parameters will be specified using
>>> a
>>> syntax similar to ImageJ2 commands' at the top of the script.
>>>
>>> Ciao,
>>> Johannes
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://imagej.net/pipermail/imagej-devel/attachments/20140219/c0274d6a/attachment-0001.html>


More information about the ImageJ-devel mailing list