Login  Register

Re: Information from Macro

Posted by Ben.BigHair on Jul 09, 2007; 1:55pm
URL: http://imagej.273.s1.nabble.com/stack-threshold-tp3698921p3698926.html

On Jul 9, 2007, at 08:32 AM, Holmes, Charlotte wrote:

> Hi
>
> I was wondering if there was an easy way for a plugin to get  
> information
> from a macro?
>
> I have an old macro I use to put a grid on an image. I have now
> developed a plugin to help analyse the image with the grid on it  
> however
> to go forward I really need the locations of the grid points.
> I could to this within the plugin but it would be a lot of work when I
> have the macro there with the information in it.


Hello,

You might want to look at IJ.runMacro() and IJ.runMacroFile(). Each  
of these will run the macro you specify, deliver arguments (as  
String) to the macro, and return a String value from the macro to the  
calling plugin.  I use this a lot with arguments (and return values)  
concatenated into a single string delimited by the "\n" newline  
character.  I often use the first line of the argument for processing  
flags - like if I want the macro to run in batch mode, etc.  If I  
need a number of processing flags in the first line, I concatenate  
those with tabs or commas.

Here is a snippet from a macro that is called by a plugin....

> arg = split(getArgument(),"\n");//split all the records, the first  
> of which holds processing info
> pi = 3.141593;
> // get the first line of flags etc.  The first line has booleans,  
> filepaths,
> //  numbers etc. in tab-delimited fields
>     s = split(arg[0], "\t");
>     doVerbose = startsWith(s[0], "true");
>     doBatchMode = startsWith(s[1], "true");
>     doEnhance = startsWith(s[2], "true");
>     doScalebar = startsWith(s[3], "true");
>     cal = parseFloat(s[4]);
>     name = s[5];
>     dir = s[6];
>     maskDir = s[7];
>     doMask = !(startsWith(maskDir, "noMask"));
>     outlineDir = s[8];
>     doOutline = !(startsWith(outlineDir,"noOutline"));
>     distNN = s[9];
>     thresh = s[10];
>     closeHoles = s[11];
>     lightOrDark = s[12];
>     minSize = pow(s[13]/2.,2) * pi;  //convert minESD to minArea
>     maxSize= pow(s[14]/2., 2) * pi; //convert maxESD to maxArea
>     slice = parseInt(s[s.length-1]);
>
> n = arg.length-1;// the number of records to process


You probably get the idea. Hope that is what you are looking for.

Cheers,
Ben