apply object ID / material ID

Hi there, is there a comfortable way of applying (globally) Object IDs or material IDs to all the meshes/materials in the scene?

ctrl + L = materials

Edit: Richards answer is better

All materials in the .blend (Python console):


for i, m in enumerate(D.materials): m.pass_index = i+1