How to select and deselect an Selection in ROIManager using a macro

I’m trying to use a macro to quickly update, select and deselect a ROI, the Problem is, after restoring the Selection, it is not selected in the ROI Manager, so i can’t update it anymore. Here is the Macro:

macro "MacroUpdate [a]" {
        roiManager("Update");
    }
macro "MacroUpdate [s]" {
        run("Restore Selection");
    }
macro "MacroUpdate [w]" {
        run("Select None");
    }

I tried to save the selected ROI (roiManager(“index”)) but it is not working.
I hope you understand the problem
Thank you

Hi,

have you had a look here for available macro functions? https://imagej.nih.gov/ij/developer/macro/functions.html .
The autocomplete in the script editor is also a great help.
Looks like you might be looking for roiManager("select", index)

Are you talking about one single Roi or a list of Rois in the Roi Manager? Can you describe some more details?

It is not possible to restore the selection of list entries in the RoiManager with

run("Restore Selection");

If you want to re-select an entry in the RoiManager you have to use roiManager("select", index) as @noreenw wrote.
And you have to store the index of the last selection temporarily.

There are at least 5 Roi in the List but I’m working only with one. I need edit this selection and it is alot easier if the selection is temporarily not visible.

Yes, I tried to save the selected roi: roiManager(“index”). But when I want to restore the selection, die Value gets lost. Do you know where i can save it and get it back?

macro "MacroUpdate [w]" {
        POS= roiManager("index");
        run("Select None");
        print('POS', POS);
    }

For Example there are 5 ROIS in the Manager. And I’m working with the first (1). If its selected I can update it by pressing A, but when I now press w the value (1) gets lost. When I tried to Restore the Selection: roiManager(“select”, POS) there is no value anymore. Where can I store the index of the last selection temporarily?

The variable POS lives probably locally in that one macro, and the moment you exit that macro it doesn’t exist any more. Is there a reason why you have so many small macros instead of a single larger one where you could keep track of the current index?

I’m also not 100pro sure I understand your issue, so posting complete code examples and/or screenshots always helps.

yes exactly. It is only local. How do I get it permanetly?
This is the complete problem :slight_smile: I just would like to have the possibility to easily modify a selection/roi with the cursor by hand.
Actually I dont know how I could how I could change it into a bigger macro would it be running all the time? Now it is more like a shortcut for a-s-w…

To permanently save a variable you can use
call("ij.Prefs.set", "myVariableKey", "desiredValueToSave");

To reload its use
previousValue = call("ij.Prefs.get", "myVariableKey", "defaultValue");

Check this:
http://imagej.1557.x6.nabble.com/Re-How-to-save-macro-variables-values-in-a-text-file-td5001804.html

Yes I found it too, but It is not working.
When I run: call(“ij.Prefs.set”, “myVariableKey”, “desiredValueToSave”);`
I get an exception. Is it working in ImageJ2 ?

In ImageJ1 I got the message
java.lang.IllegalArgumentException: Key must have a prefix

Try the following commands

call("ij.Prefs.set", "ij.myTestKey", "3.1415");

preVal = call("ij.Prefs.get", "ij.myTestKey", "-0.99");
print(preVal);

Thanks a lot ! It’s working!