Simple material id script for masking?

in The Commons
Is there a script like Oso Toon Shader but simpler?
- Set all elements in scene to one same material id
- Set selected element in scene and in its tree elements to one specific (or random) material id
The intention is to e.g. get a mask in a complex scene for one figur with its components like hair and outfit.
With Oso Toon Shader I get different colors for the figure’s components like hair and outfit.
But perhaps I do something wrong or miss something.
Comments
I don't use the Material ID canvas for masking as it's usually too jaggedy to be of much use, especially for hair. You get a very accurate mask when using the Alpha setting.
You'll also want to create a canvas with nothing selected, of course.
Thank you very much.
Yes, you are right regarding hair. I guess also with transparent material.
It works and also well with intersections of non-selected objects.