Login  Register

Re: problems migrating frpm macros to API

Posted by Graeme Ball-2 on Feb 05, 2015; 3:24pm
URL: http://imagej.273.s1.nabble.com/problems-migrating-frpm-macros-to-API-tp5011457p5011458.html

Hi Aryeh,

You can use the macro recorder to record java code instead of macro
commands, and translate the java to python. e.g. with
  Plugins > Macros > Record  "Java"
selected, I get the following java code when clicking
  File > Import Image Sequence...

IJ.run("Image Sequence...", "open=/path/to/files autoscale
color_mode=Default quiet view=Hyperstack stack_order=XYCZT number=8
file=filename_pattern sort autoscale color_mode=Default quiet
view=Hyperstack stack_order=XYCZT");


which can be converted to the jython script:

from ij import IJ

IJ.run("Image Sequence...", "open=/path/to/files autoscale
color_mode=Default quiet view=Hyperstack stack_order=XYCZT number=8
file=filename_pattern sort autoscale color_mode=Default quiet
view=Hyperstack stack_order=XYCZT")


If you want a list of open files, try the IJ.WindowManager:

  http://rsb.info.nih.gov/ij/developer/api/

e.g. here is some jython code that prints window titles:


from ij import WindowManager


windowIDs = WindowManager.getIDList()

windowTitles = [WindowManager.getImage(i).getTitle() for i in windowIDs]

for t in windowTitles:

    print t




On Thu, Feb 5, 2015 at 2:28 PM, Aryeh Weiss <[hidden email]> wrote:

> I am once again trying to work in python, and am encountering difficulties.
> I have trouble knowing how to find the methods that correspond to commands
> in macros
> For commands that appear in the menus, I can use the Command finder, but I
> dont know what to do with
> something like isOpen(imageTitle), or many other macro features that are
> not part of the command menu structure.
> WindowManager has a method for returning a list of nonImageWindows, but
> where do I get a list of image windows?
>
> Even when I find the method, I dont always know how to handle the
> arguments. For example:
> IJ.run("Image Sequence...", "open="+inputDirPath+"
> file=x"+str(xLoc).zfill(3)+"_y"+str(yLoc).zfill(3)+" sort")
> will open an image sequence, appropriately filtering the file names.
> When I try to do it with FolderOpener(), I see how to create a filtered
> file list (getFilteredList), butI dont see how to pass that filtered list to
> openFolder(). So openFolder opens everything in the director (about 275
> images instead of 11)
>
> I think that I am not the only one who started with the IJ macro language,
> so my main question is, how can I find the methods that correspond to the
> macro commands -- particularly the ones that are not in the menus?
>
> Right now, I hope someone can tell me how to open that sequence with the
> filtered list, and which method provides a list of open image window titles.
>
> Thanks in advance for your help.
>
> --aryeh
>
> --
> Aryeh Weiss
> Faculty of Engineering
> Bar Ilan University
> Ramat Gan 52900 Israel
>
> Ph:  972-3-5317638
> FAX: 972-3-7384051
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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