I am trying to apply a series of commands to each slice in an image stack. I was planning to make an array containing the commands as strings and then pass it to a user defined function which apply these commands in order to each slice.
eg: command=newArray(‘setTool(“wand”);’,‘doWand(pos, pos);’);
but i am not able to execute these strings. i have tried using doCommand , run() , exec().
Here is an IJ Macro (IJM) script that shows how to do this
// set up array of commands to run
cmds = newArray (10);
cmds = "print (\"running commands ...\");"
cmds = "newImage (\"sample\", \"RGB noise\", 256, 256, 1);";
cmds = "makeRectangle (40, 40, 50, 50);"
cmds = "setColor (0, 255, 0); fill();"
cmds = "Roi.remove;"
cmds = "print (\"done!\");"
// run the commands using eval()
for (i = 0; i < cmds.length; i++)
if (cmds[i] != 0)
(You could do more or less the same thing using other scripting
languages, such as jython (python).)
Note the use of “backslash” to escape the “double-quote”
character used to delimit string arguments within command
However, this seems an odd thing to want to do. Perhaps if
you give us a little more information about your use case
people here could make suggestions about how to accomplish
your goal using more “normal” scripting techniques.
Hey thanks for your time and effort. Yes I had similar plan too but wanted to do it the way i chose so that it can reused easily somewhere else and easily modified to will (just add commands to an array and call function to apply these command to each slice).