@imagejan, @Wayne, I think I got it.
There are 3 commands to set the position of a ROI:
Roi.setPosition(slice) - Sets the selection position. Requires 1.53b.
Roi.setPosition(channel, slice, frame) - Sets the selection position.
and
RoiManager.setPosition(i)
and we have also roiManager("Associate", "false");
or roiManager("Associate", "true");
I found that no mater if roiManager("Associate", "...");
is true or false the ROIs the ROIs in this macro are always associated to the correct C, Z or T.
Example macro that creates an HyperStack with 10 C, Z &T:
run("Fresh Start");
newImage("HyperStack", "8-bit composite-mode", 100, 100, 10, 10, 10);
roiManager("Associate", "false"); // or "true"
for (i = 1; i <= 10; i++) {
Stack.setPosition(i, i, i);
makeOval(42, i*8 , 7, 11);
run("Invert", "slice");
roiManager("add");
}
That being said there are cases where the ROIs are not associated with the slices but I can’t make it happen with a macro using the roiManager("Associate", "...")
command.
I will use the macro below as the basis for more observations:
run("Fresh Start");
newImage("HyperStack", "8-bit composite-mode", 100, 100, 1, 1, 10);
roiManager("Associate", "false");
for (i = 1; i <= nSlices; i++) {
setSlice(i);
makeOval(42, i*8 , 7, 11);
run("Invert", "slice");
//RoiManager.setPosition(i);
//Roi.setPosition(i);
//Roi.setPosition(0, i, 0);
roiManager("add");
//RoiManager.setPosition(i);
//Roi.setPosition(i);
//Roi.setPosition(0, i, 0);
}
for (i = 0; i < roiManager("count"); i++) {
roiManager("select", i);
//RoiManager.setPosition(i);
//Roi.setPosition(i);
//Roi.setPosition(0, i, 0);
//roiManager("update");
Roi.getPosition(channel, slice, frame);
print("ROI " + i + " is in channel :" + channel + " ,Slice " + slice+ " ,frame " + frame);
}
RoiManager.setPosition(i);
is the command that confuses me the most:
If I run it before roiManager("add");
then
Roi.getPosition(channel, slice, frame);
print("ROI " + i + " is in channel :" + channel + " ,Slice " + slice+ " ,frame " + frame);
}
always outputs the total number of slices for slice
except for the last ROI:

and in the ROI properties it is
position 10 except for the last ROI
and the ROIs are no longer associated with a slice
If I run RoiManager.setPosition(i);
immediately after roiManager(“add”);` then all the ROIs are set to 10:
and the ROIs are no longer associated with a slice
If I run RoiManager.setPosition(i);
immediately after roiManager("select", i);
then Roi.getPosition(channel, slice, frame);
outputs

but the ROI properties are set to the slice number but shifted by 1 and the ROI is associated to a slice but with a shift of 1 slice. I am guessing this is a bug.
If I run Roi.setPosition(slice)
or Roi.setPosition(channel, slice, frame)
before roiManager("add");
then everything works as expected:
Roi.getPosition(channel, slice, frame);
outputs the expected values and the ROI properties are also as expected.
If I run Roi.setPosition(slice)
or Roi.setPosition(channel, slice, frame)
immediately after roiManager("add");
then nothing happens and Roi.getPosition(channel, slice, frame);
outputs 0
and the ROI position in the properties are set to none
.
If I run Roi.setPosition(slice)
or Roi.setPosition(channel, slice, frame)
immediately after roiManager("select", i);
then Roi.getPosition(channel, slice, frame);
outputs the correct values but the the ROI position in the properties are still set to none
.
And to finish this, if I run roiManager("update");
immediately after roiManager("select", i);
without doing anything else then Roi.getPosition(channel, slice, frame);
outputs only 0
but the ROI position in the properties are set to the correct values. (if I don’t “update” the roi then the default ROI position in the properties is none
)
@oburri,
Now, for BIOP/ijs-TrackMate - ijs-Run-TrackMate-Using-RoiManager-or-ResultsTable scrpt to work properly as far as I can see what matters is that ROI position in the properties are set to the correct values regardless of the Roi.getPosition(channel, slice, frame);
outputs. Also in the ROIs properties only the slice should be set
without any information about the other dimensions 
So basically there are different ways of making it work, but in any case what matters is the the ROI properties to be set properly.
So to conclude, it appears to me that the best way to set the position of ROI is to do it after the selection is done but before adding it to the ROI manager using one of this two:
Roi.setPosition(slice) - Sets the selection position. Requires 1.53b.
Roi.setPosition(channel, slice, frame) - Sets the selection position ( //this one is not compatible with the ijs-Run-TrackMate-Using-RoiManager-or-ResultsTable script) .
Attempting to set the position of the ROI after it was added to the manger may not set the properties properly.
All of this was done with Imagej 1.53g
This is it, I hope this will help others that need to set the correct properties to their ROIs.