2
$\begingroup$

I've implemented a simple script to get pass index of objects in a scene:

def list_all_objects():
    for o in bpy.data.objects:
        print(f"Name: {o.name}, index: {o.pass_index}")
    return

But all indexes in the output are 0:

Name: Area.000, index: 0
Name: Area.001, index: 0
Name: Area.002, index: 0
Name: Area.003, index: 0
Name: Bottle, index: 0
Name: Camera, index: 0
Name: Floor, index: 0
Name: Sticker, index: 0
Name: Straw, index: 0

So that means pass indexes are initialized by 0. Is there any API to initialize these indexes so that they are distinguished?

$\endgroup$
2
  • 1
    $\begingroup$ nope, AFAIK you have to do that manually (or by script/add-on) $\endgroup$
    – Chris
    Mar 4 at 9:07
  • 1
    $\begingroup$ Of course they are all 0. This is the Pass Index value which you find under Object Properties > Relations and it is a render pass, similar to the Pass Index in the Material Properties. This is no indexing to serially number the objects in the scene. This index is used (if enabled under View Layer > Passes) to separate objects in the Compositor by filtering/masking per index. $\endgroup$ Mar 4 at 9:26

1 Answer 1

4
$\begingroup$

and since you already wrote that, script, just add a few lines:

def set_pass_indices():
    counter = 1
    for o in bpy.data.objects:
        print(f"Name: {o.name}, index: {o.pass_index}")
        o.pass_index = counter
        counter = counter + 1
        print(f"after: Name: {o.name}, index: {o.pass_index}")
    return

and you get what you want ;)

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .