Macro does not work when a new image is opened for the second time

Hello everybody,

I have a problem with the next lines of my script:

//This macro is not able to select the area for the second time that an image is opened
  run("Open...");
setTool("point");
waitForUser("Click over the circle and then press 'OK' to continue. Choose the tolerance moving the bar tolerance");
    getSelectionCoordinates(x, y);
    for (i=0; i<x.length; i++){
		doWand(x[i],y[i]);
		run("Wand Tool...");
	}

At the first time, the script goes well but when I close and open a new image to evaluate it, I can point the image although the tolerance bar does not work

What is happening? could someone help me, please?

I attach in this comment the script and some images of the evaluation.

Greetings

Luis

I think it’s because the wand tool window becomes the primary window and not the image. Add the following line to your code -

for (i=0; i<x.length; i++){
selectWindow(“Black_circle.jpg”);
doWand(x[i],y[i]);
run(“Wand Tool…”);

This way each time your for loop runs, the image becomes the primary image/window.
Please let me know if it works.

Regards,
Somsubhro

Hello @somsubhro!

Firstly, thanks for your reply.

I’ve check the code line in my script and it isn’t work, unfortunately.

Regards.

Luis

Hello @Professor_OAT,

Sorry, I think I misunderstood your problem.

Could you please share some example images that you’re working on?

Just to make sure I understand correctly - you are doing this to analyze/measure the circles?

Thank you.
Kind regards,
Somsubhro

Hey Professor,

I didn’t even work it out when I tried it manually.

However, the following code works (it runs a “dry” Wand over the image automatically and then lets you choose the tolerance and everything). It seems that there needs to be a selection before this selection can be altered/modified:

run("Open...");

setTool("point");
waitForUser("Click over the circle and then press 'OK' to continue. Choose the tolerance moving the bar tolerance");
  	
getSelectionCoordinates(x, y);
	
run("Wand Tool...", "mode=Legacy smooth tolerance=20"); 
doWand(x[0], y[0]);
run("Wand Tool...");
    

I also shortened the code a little bit, because a “for” loop for one loop isn’t really doing anything.

Let me know if it helps and is the way you intended it to be.

Hi @somsubhro and @spamhunter. My apologizes for taking along time to answer. Thanks for helping me to find the answer of my issue. @spamhunter ’ s code was the solution of my issue.

Greetings.

Luis