Here's how you do it:
Select all the objects you want to change
For the active object (last one selected), change the Pass Index to the Index ID you want.
Right click on the Pass Index field and select "Copy to Selected" from the menu
All the objects should now be updated to the same index ID.
You ask a question to which there is no simple answer based on your requirements:
no python - this limits any automation and implies a lot of work
with anti aliasing - this is something cycles cannot do yet on masks
The anti-aliasing issue of ID masks (first render, second without, last with):
The perfect solution would be to render the scene with each ...
Similar to @Carlo's answer you can set this up within a single blendfile (and within the same scene) by making use of the Render Layers 'material override' setting. Set up each object with a pass index relating to the type of material in use. For example, we could have :
0 = Black diffuse (obscures mask)
1 = Emissive (the thing we want the mask for)
2 = ...
I don't think it's possible to utilize material (or object) index behind a refractive material as it is.
Blender is correctly showing the mask of the object that form the camera point of view truly has the material assigned. The squared piece is made of glass, the fact that is somehow showing what's behind doesn't change the material which is made of.
You could use a 'binary encoding' technique to allow you to assign each object to a limited number of groups.
To achieve this, allocate each group a power of 2 :
Group 1 = 2^0 = 1
Group 2 = 2^1 = 2
Group 3 = 2^2 = 4
Group 4 = 2^3 = 8
Group 5 = 2^4 = 16
You can combine these 'groups' by simply adding them together :
Groups(1,3,4) = 1 + 4 + 8 = 13
Your setup seems to be correct.
The material you want to use as mask must have an Pass Index number.
In the render layers enable Material Index
Now press F12: YOU HAVE TO RENDER THE IMAGE for this changes to update, and the compositor has the proper information to work with (Sounds simple, but this step is sometimes overlooked).
After that, the node ...
This is pretty weird. I can think of three possible workarouds:
Render the eye as a separate object, then use Object Index.
Render the eye on a separate RenderLayer.
As the eye seems to be pretty much an emission material, you could separate the emission pass.
Each material can have it's own Pass Index set up in the Properties Window > Material > Settings > Pass Index
If you set them up correctly after rendering, using a Compositor you can use an ID Mask node to mask out each part of the image according to material.
It can be directly from the Render Layers node or from an Image node through a multi layer file ...