Selecting Multiple ROIs with Jython RoiManager

Hello everyone,

I am trying to select multiple ROIs with the RoiManager in Jython.
I import:
from ij.plugin.frame import RoiManager
RM = RoiManager()
rm = RM.getRoiManager()

Then rm.select(2) works but I cannot find any way to select multiple ROIs. When I call rm.select(4) only the ROI at index 4 is selected.

I’m aware of the roiManager(“Select”, newArray(0,1)); logic but there doesn’t seem to be a rm.select equivalent.

rm.select([2,4]) raises an error.

Any input is appreciated. Thank you for your help.

Kind regards,
Daniel

Hi Daniel,
You are probably looking for the
rm.setSelectedIndexes(array) method.

2 Likes

Hey @scidanm,

if you activate the Macro Recoder and select language “Java”, you can observe that it records this while selecting multiple ROIs in the ROI Manager:

rm.setSelectedIndexes(new int[]{3,4,5,7,9});

You can then translate it to Jython:

rm.setSelectedIndexes([3,4,5,7,9]);

Cheers,
Robert

1 Like

Hello Robert and Thomas,

Thank you both for the prompt response. You are correct. rm.setSelectedIndexes([3,4,5,7,9]); does the job. Actually, my macro recorder is not recording anything that happens in the ROI manager, making this quite a bit harder.

Best,
Daniel

1 Like