Using duplicates in ImageJ macros

I know that command and ive tried it too… but it also results in that error of undefined variable…

Did you understand the concept of variables?

In your case, you didn’t define a variable named id. You have to replace the placeholder id from the documentation by the name of your variable, original, as I proposed in the code snippet in my previous post.

2 Likes

Good day!

Did you read:

getImageID()
“Returns the unique ID (a negative number) of the active image. Use the selectImage(id), isOpen(id) and isActive(id) functions to activate an image or to determine if it is open or active.”

and

selectImage(id)
“Activates the image with the specified ID (a negative number). If id is greater than zero, activates the idth image listed in the Window menu. The id can also be an image title (a string).”

  1. You use both calls like this:

    myID = getImageID();  // get the id (**a negative number**) of the frontmost image
    // do whatever you want with whatever images
    // ...
    // if you now need to work on the  image with id 'myID' then use
    selectImage(myID);// activate the image with id 'myID'
    
  2. Alternatively use:

    myImageName = getTitle();  // get the title **string** of the frontmost image
    // do whatever you want with whatever images
    // ...
    // if you now need to work on the  image named 'myImageName' then use
    selectImage(myImageName);// activate the image named 'myImageName'
    

Don’t mix both approaches!

HTH

Herbie

1 Like

May I ask who has edited my post and why the remark to not mix the two approaches was deleted.

Editing should be left to the poster!

Herbie

I edited to improve the formatting only. The remark was still there (100% agreed that editing should never be done to change the content of someone else’s post!), but due to a bug in the Markdown support, it was not being shown. I will edit again to fix matters.

I also agree 100% that these two approaches should not be mixed. :grin:

1 Like

Thanks Herbie, it makes sense, and i wont mix these two approaches :slight_smile: