One thing that might help you is to take advantage of the fact that the
Dialog.addDirectory macro function supports drag-and-drop. So you can then
write a macro wrapper which reads the dropped path and decides what to do with
each file. See this example, which opens all *.gif files in the dropped folder:
requires("1.52s"); //File.setDefaultDir(directoryPath)
requires("1.53d"); //Dialog.addDirectory(label, defaultPath)
run("Close All");
print("\\Clear");
defaultDir = getDir("imagej") + "samples\\";
File.setDefaultDir(defaultDir);
Dialog.create("Example Dialog");
dirLabel = "Dir";
dirPath = getDir("imagej") + "samples";
Dialog.addDirectory(dirLabel, dirPath);
fileLabel = "File";
filePath = getDir("imagej") + "samples\\blobs.gif";
Dialog.addFile(fileLabel, filePath);
virtual = true;
Dialog.addCheckbox("Virtual Stack", virtual);
Dialog.show(); //waits until the user clicks "OK" or "Cancel". The
macro terminates if the user clicks "Cancel".
dirPath = Dialog.getString();
filePath = Dialog.getString();
virtual = Dialog.getCheckbox();
if (!dirPath.endsWith("\\")) dirPath += "\\";
print("dirPath: " + dirPath);
print("filePath: " + filePath);
print("virtual: " + virtual);
pattern = "(\\.gif$)";
allFiles = getFileList(dirPath);
matchedFiles = Array.filter(allFiles, pattern);
for (i = 0; i < matchedFiles.length; i++) {
print("file: " + matchedFiles[i]);
open(dirPath + matchedFiles[i]);
//call your plugin here
}
This would work fine with custom file formats as well, as the macro is agnostic
to the type of the files that are handled. I just tried this with an extension
for a custom format I added myself to HandleExtraFileTypes and it worked, using
the open() command.
A different approach is to create a script in your OS in a language that
supports drag-and-drop so that you create your wrapper macro in there, and feed
the images to ImageJ. The advantage with this approach is that you can easily
integrate it with a right-click menu in your OS so that you do not need to look
up the drop target. The disadvantage is that it is less obvious to the user how
this works, it would be a black-box if the context menu is not intuitive. With
a dialog you can add whatever options and explanations you want for the user.
An even fancier approach is to combine everything in a hybrid script that your
OS treats as a script and ImageJ treats as a macro. You do this by writing code
that the other language ignores as a comment or dummy variable assignment. This
works because macros can be run explicitly as a file with any extension. So you
can thus drag-and-crop the folder on an icon or menu choice in your OS, _or_
you can launch the script via ImageJ and drop the folder on the dialog field
using the same code. I can perhaps write an example for that as well, but I am
on Windows so if you are on another OS I would not know how this works there. I
often use hybrid scripts, but I have not yet tried with dialog code as I
normally use them for headless macros.
Stein
-----Original Message-----
From: Curtis Rueden <[email protected]>
Sent: 28. februar 2024 22:10
Subject: Re: Advice for Virtual Stack of Entire Folder
Hi Alan,
ImageJ does not support drag-and-drop of folders—they are always handled in a
hardcoded way that cannot delegate to HandleExtraFileTypes. Some Fiji devs
actually did some exploratory work recently to make it possible to support
drag-and-dropping folders in Fiji (thanks to imagej-legacy's bytecode patching
of ij), but it is not yet merged and released.
- https://github.com/scijava/scijava-common/pull/473
- https://github.com/imagej/imagej-legacy/pull/302
Unfortunately, in our most recent testing (in Oct 2023), we found it was not
yet working as intended, and I believe no one has had time to work further on
it for the moment. I may revisit it in April 2024 at an upcoming
BigDataViewer/ImgLib2 hackathon, we'll see.
Regards,
Curtis
On Wed, Jan 17, 2024 at 11:14 AM Alan Brooks <[email protected]> wrote:
> I'm looking for advice on how one might trigger a custom plugin that
> treats an entire folder of multi-frame files as a virtual stack. I
> have written up a plugin that does that but was not able to figure out
> how to integrate it with HandleExtraFileTypes. For now I just made a
> button to call the plugin directly but would be curious to find how to
> support it via drag-and-dropping the folder.
>
> Thanks,
> Alan
>
> --
> ImageJ mailing list:
> http://image/
> j.nih.gov%2Fij%2Flist.html&data=05%7C02%7Cstein.rorvik%40sintef.no%7C0
> f813228cb7e4c42b49b08dc38a1c6ad%7Ce1f00f39604145b0b309e0210d8b32af%7C1
> %7C0%7C638447514677535538%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAi
> LCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=oDce
> NAAE0TKJMdSuziJmQiVQUGB%2BSrE6fJl%2FdELDLAs%3D&reserved=0
>
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html