doCommand() with user defined functions

Hi All,

It seems like doCommand() can only be used on menu functions, but would be helpful to use it to multitask user macros. For example, after completing some conversion on a folder, the macro could go start both the next folder conversions and process converted tiffs in first folder. The computer I am using has 24 cores.

Thanks!
Best,
Ferdinando

1 Like

Hi @Fepu,

you can save whatever macro you want to run in a subfolder of ./Fiji.app/scripts/ and it will appear in the menus (and therefore be callable with doCommand).
For example, if you save your macro at ./Fiji.app/scripts/Plugins/My_Macro.ijm, you can call it with:

doCommand("My Macro");

Hope that helps.

1 Like

Thanks @imagejan it does help. I will need to figure out how to pass variables to the macro though. This is what I’m trying to do:

cohort = getDirectory("Select the cohort folder containing slide folders");
suffix = ".svs";
setBatchMode(true);
run("Bio-Formats Macro Extensions");
slidelist = getFileList(cohort);
Array.sort(slidelist);

// ### FOLDERS ###
// Registered folder under cohort (main folder)
reg = cohort+"Reg"+File.separator;
if (!File.exists(reg)) {
	File.makeDirectory(reg);
}
// output folder under cohort (main folder)
tiff = cohort+"Tiff"+File.separator;
if (!File.exists(tiff)) {
	File.makeDirectory(tiff);	
}

// ### 
// s as in slide
for (s=1; s<slidelist.length+1; s++) {
	filelist = getFileList(cohort+slidelist[s-1]);
	Array.sort(filelist);
	// m as in marker
	for (m=1; m<filelist.length+1; m++) {
		// avoids files in Tiff and Reg folder
		if(endsWith(filelist[m-1], suffix)) {
			// make same name folders under Tiff folder
			if (!File.exists(tiff+slidelist[s-1])) {
				File.makeDirectory(tiff+slidelist[s-1]);	
			}
			if (!File.exists(tiff+slidelist[s-1]+File.separator+filelist[m-1]+".tif")) {
				print("Opening: "+slidelist[s-1]+File.separator+filelist[m-1]);
				Ext.openImagePlus(cohort+slidelist[s-1]+File.separator+filelist[m-1]);
				run("Stack to RGB");
				saveAs("Tiff", tiff+slidelist[s-1]+File.separator+filelist[m-1]+".tif");
				close("*");
			}
		}
	}
	// make same name folders under Reg folder
	if (!File.exists(reg+slidelist[s-1])) {
		File.makeDirectory(reg+slidelist[s-1]);	
	}
	// get reference file name for registration (first Hem?)
	for (m=1; m<filelist.length+1; m++) {
		if (matches(filelist[m-1], "C01R1")) {
			ref = filelist[m-1];
			break;
		}
	}
	// THIS KEEPS POPPING A GUI FOR REF FILE
	run("Register Virtual Stack Slices", "Source directory="+tiff+slidelist[s-1]+" target_dir="+reg+slidelist[s-1]+"  reference_name="+ref+" use_shrinking_constraint=false");
}

I would like to run Register Virtual Stack Slices as a separate thread, to take advantage of the multicore workstation I’m using. I do not know Jython, Java, Matlab, … so any solution involving switching scripting language would have a steep learning curve for me. I still have issues with that command anyway, as you see in the code above (and in this thread)…

Thank you!

Best,
Ferdinando

@imagejan would you mind suggesting how to pass variables to installed macros?

I can call a macro with doCommand("My Macro"); but if I call a var inside the macro it reports undefined variable. Also declaring it as global var does not work. Thank you