How to apply Index Pass data to multiple objects ?

Hi ! I came across a problem : I’ve got a scene with a lot of animated objects that I want to isolate while compositing but selecting them one by one and changing the Index Pass would take me ages, so I’d like to know if there’s a way to apply Index Pass data to multiple objects at once ? Like the linking function for materials etc. (ctrl L)

My apologies if it’s a stupid question, but I’m still a newbie…

Thank you !

Altering multiple parameters can sometimes be a chore. If there is no tool available, that is where code comes in. Here is a simple code solution. Paste this code in to an new text window and run the code.

import bpy

for ob in
    if ob.type == 'MESH' or ob.type == 'CURVE' or ob.type == 'FONT':
        ob.pass_index = 1

Any object that is in your scene and is a mesh, curve or font will be set to index #1.

Code variations could be like this as well…

import bpy

for ob in
    if ob.type == 'MESH': 
        ob.pass_index = 1
    if ob.type == 'CURVE':
        ob.pass_index = 2
    if ob.type == 'FONT':
        ob.pass_index = 3
    if == 'Cube':
        ob.pass_index = 8

So decide how you want to detect your large group of objects and write an IF statement to cover that case.

Here is another variation that will change the pass_index of any object that has the Array modifer first in the stack to #1.

import bpy

for ob in
    l = len(ob.modifers)
    if l > 1:
        mod = ob.modifiers[0]
        if mod.type == 'ARRAY':
            ob.pass_index = 1

sorry for the question, but If I want to change to a random number all the index pass of all the objects of the scene and randomize all the material index of the scene?
Thanks for your help!

That is kind of a weird request. Each time you ran the code, you would have to re-wire your output nodes because the nodes reference the index numbers. If they are randomized you would be faced with resetting up or at least tweaking the composite nodes.

Randomization can be handled by python directly.