Problem with writing a Macro

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with writing a Macro

Vanessa
Dear all,

I have problems with my Macro. I want to open all images in a directory, one
by one, then make a rectangle which I want to move per hand (by user) and
then accept, duplicate and save the duplicate. However, my Macro does not do
anything when trying to run it. Could you help me what is wrong??

Thanks!

input = "Z:\Zellkultur\Ca-Imaging Daten\B339\2018-01-30\DG 2\";
output = "Z:\Zellkultur\Ca-Imaging Daten\B339\2018-01-30\DG
2\Base_SelectionWindow\";

list = getFileList(input);
    setBatchMode(false);
for(i=0;i<list.length;i++){
    open(input+list[i]);
    name = getTitle();


selectWindow(name);
run("Specify...", "width=455 height=1058 x=0 y=0");
makeRectangle(0, 18942, 455, 1058);
waitForUser("change Rectangle, then hit OK")
run("Duplicate...", " ");
saveAs("TIFF", output + filename);
close();
}







--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Problem with writing a Macro

Herbie
Good day Vanessa,

here is a macro that works:

// start
dir = getDirectory( "Choose a Directory" );
list = getFileList( dir );
for( i=0;i<list.length;i++ ){
   open( dir + list[i] );
   run( "Specify...", "width=455 height=1058 x=0 y=0" );
   waitForUser( "Change Rectangle, then hit OK" );
   run( "Duplicate...", " " );
   saveAs( "tiff", dir + File.nameWithoutExtension + "_excerpt.tif" );
   close();
   close();
}
// end

It doesn't use provided path strings, i.e. you have to choose a
directory with the images and it saves the excerpts in the same
directory with suffix "_excerpt".

You may change this macro to make it work with path strings but please
try it first!

Furthermore make sure that the selection that is provided by
"Specify..." makes sense for the size of your images.

Regards

Herbie

:::::::::::::::::::::::::::::::::::::
Am 06.02.18 um 11:10 schrieb Vanessa:

> list = getFileList(input);
>      setBatchMode(false);
> for(i=0;i<list.length;i++){
>      open(input+list[i]);
>      name = getTitle();
>
>
> selectWindow(name);
> run("Specify...", "width=455 height=1058 x=0 y=0");
> makeRectangle(0, 18942, 455, 1058);
> waitForUser("change Rectangle, then hit OK")
> run("Duplicate...", " ");
> saveAs("TIFF", output + filename);
> close();
> }

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Problem with writing a Macro

Michael Schmid
In reply to this post by Vanessa
Hi Vanessa,

for Strings that contain the backslash character, you have to write
double backslashes:
   input = "Z:\\Zellkultur\\Ca-Imaging Daten\\B339\\2018-01-30\\DG 2\\";

A single backslash followed by another character would be a special
character, e.g. '\n' is the linefeed character, '\t' is tab, and \201 is
interpreted as the character with octal code 201.

You can use
   print(input);
to see whether the String has been interpreted correctly.


Michael
________________________________________________________________
On 06/02/2018 11:10, Vanessa wrote:

> Dear all,
>
> I have problems with my Macro. I want to open all images in a directory, one
> by one, then make a rectangle which I want to move per hand (by user) and
> then accept, duplicate and save the duplicate. However, my Macro does not do
> anything when trying to run it. Could you help me what is wrong??
>
> Thanks!
>
> input = "Z:\Zellkultur\Ca-Imaging Daten\B339\2018-01-30\DG 2\";
> output = "Z:\Zellkultur\Ca-Imaging Daten\B339\2018-01-30\DG
> 2\Base_SelectionWindow\";
>
> list = getFileList(input);
>      setBatchMode(false);
> for(i=0;i<list.length;i++){
>      open(input+list[i]);
>      name = getTitle();
>
>
> selectWindow(name);
> run("Specify...", "width=455 height=1058 x=0 y=0");
> makeRectangle(0, 18942, 455, 1058);
> waitForUser("change Rectangle, then hit OK")
> run("Duplicate...", " ");
> saveAs("TIFF", output + filename);
> close();
> }
>
>
>
>
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html