Login  Register

Re: Macro help - result file save

Posted by Wayne Rasband on Jan 15, 2009; 4:52pm
URL: http://imagej.273.s1.nabble.com/Macro-help-result-file-save-tp3694038p3694039.html

On Jan 15, 2009, at 10:57 AM, Wu, Yuhong wrote:

> Hi All,
>
> I have a question regarding writing macro to save result files from
> "analyze particle".
>
> As an exmaple, I can open an image and run analyze particle and save
> measurements into an excel file in a pre-defined folder with a
> pre-defined name : saveAs("Measurements", "C:\\Documents and
> Settings\\Desktop\\Results.xls"); ".
>
> But what I would like to do is to use getDirectory("image") and
> getTitle("image") so to save the excel file:
> (1) in the folder that contains the image and
> (2) with a title that reflects the image being analyzed, say "Results -
> xx.xls" (xx is the image name).
>
> For some reason, I can create new images and save those as I wanted.
> But
> not for the results.xls files.
>
> Any help is greatly appreciated -  thanks in advance!
>
> Yuhong

Here is macro that does this. It removes the extension from the image
title and replaces it with ".xls" because saveAs("Measurements", path)
doesn't do it, although it probably should.

   open("");
   run("Measure");
   dir = getDirectory("image");
   name = getTitle;
   index = lastIndexOf(name, ".");
   if (index!=-1) name = substring(name, 0, index);
   name = name + ".xls";
   saveAs("Measurements", dir+name);
   print(dir+name);

-wayne