Good evening, @MArtur! Sorry it has taken this long for you to get an answer. If I understand correctly, you want to be able to change your Object ID value to cycle through your objects and output an image with that object transparent in the file output?
If that is what you want, the reason your original approach didn’t work was because of your choice of the Mix node. I can’t exactly say the reason why as those blending modes are some black magic defined mathematically by Adobe (the Blender manual has a page on the Color-Mix node, but it refers to the glossary which refers to the Gimp mix nodes which only lists “Hard Mix”, and still that is only defined as TODO). But…What I expect is happening is that alpha is not considered when using the Mix mode - or it is additive. Where you are trying to mix the bottom value (the white image input) with the render using the object as a mask, you won’t be able to lower the alpha value of the cube using the Mix mode. I’ve come up with two options - one that is much easier, but the output isn’t as pretty, and the other that is slightly more difficult, but it has cleaner margins. I’ll show the methods here and upload the .blend files, as well.
Method 01 (cleaner): Manually subtract the alpha of the object from the overall image and insert that alpha back into the original image:
Method 02 (easier): Use the Alpha Over node and an input with zeroed out alpha with the ID Mask node as the factor:
Invisible_Cube01.blend (845.4 KB)
Invisible_Cube02.blend (824.6 KB)
If you solved this for yourself, please share your method! Have a great night!