python find material that is not used I am not a blender developer, but a python developer. I wanna create some validation scripts that I can use to assure that we don't keep orphan nodes in the blend file. One thing that I wanna do is to find out if there are any NOT used materials in the file. I wanna implement the is_used method below, that should return True only if the material is used in the blend file, and False if it is an orphan material that is just remaining in the blend file.

def is_used(material):
    pass

for material in bpy.data.materials:
    if not is_used(material):
        print('material %s is not used' % material)
Like Chebhou mentioned, you can use material.users to find out how many users there.

So you should use this in your method:

def is_used(material):
    if material.users == 0:
        return False
    else:
        return True


Or because it is a very simple condition, it would be more effective to not use a separate function at all:

for material in bpy.data.materials:
    if material.users == 0:
        print('material %s is not used' % material)


Also, the new str.format() in Python 3 should be used to fit the new standard (but it isn't really necessary). You can also use material.name for a prettier output.

print('material {} is not used'.format(material.name))