Login  Register

Re: Resetting focus of Open Next

Posted by Michael Schmid on Mar 04, 2010; 5:52pm
URL: http://imagej.273.s1.nabble.com/Resetting-focus-of-Open-Next-tp3689114p3689117.html

Hi Bob,

ij.io.OpenDialog has public static getDefaultDirectory() and  
setDefaultDirectory(String defaultDir) methods.

You can use these (even in a macro, by the 'call' command).

Michael
________________________________________________________________

On 4 Mar 2010, at 01:10, Bob Loushin wrote:

> I am writing a plugin which needs to process all of the image files  
> in a folder. To save myself having to manage filenames, I'm using  
> Open next, so my code looks something like this:
>
> <User opens an image>
> <User starts the plugin>
> <User uses plugin to change image>
>
> //At this point, I need to save the changed image without  
> overwriting the initial data.
> //I'm trying to do something like:
> FileInfo fileInfo = Image.getOriginalFileInfo();
> IJ.save(image, fileInfo.directory + "Processed versions\\" +  
> fileInfo.fileName);
>
> //Now I move on to the next image in the folder, using the line
> IJ.run("Open Next");
>
> <User uses plugin to change next image>
> <Continue until I get back to the first image>
>
> The problem is, the IJ.save resets the current folder, so when the  
> Open Next runs, it is now pointing at the wrong folder.
>
> I can see several possible solutions: Save the processed images in  
> the same folder as the originals (but then the Open Next will start  
> picking them up and presenting them to the user!). Find a way to  
> save which doesn't reset the current folder (looked around, but  
> didn't see one. Anybody know of one?). Reset the current folder  
> somehow so that the Open Next will find the correct next file. Or  
> scrap this approach and try another, probably going through the  
> hassle of reading the folder, building a list of files in it,  
> figuring out which ones are actually images, and then opening the  
> next one myself (seems a shame to do all this when Open Next is out  
> there).
>
> I found a promising looking function in the ImageJ API documention.  
> IJ.getDirectory will tell me where I am. Unfortunately, there seems  
> to be no corresponding IJ.setDirectory which would allow me to  
> reset it in the program. Several other approaches all caused dialog  
> boxes to pop up. If I knew what variable IJ.getDirectory was  
> reading, I might be able to reset it directly, but I haven't  
> managed to find that in the documentation, either.
>
> I suspect there are others who've done something like this, and I'm  
> missing an easier way. Thanks to anyone who can offer any suggestions.