No Material Selection Script

NO MATERIAL SELECTION SCRIPT

This script I wrote might come in handy if you somehow find yourself working on a scene with many different parts/objects that do not have any materials: this script selects all those objects.

How it works: If you have a scene with one or more objects that never were assigned materials, load this script in a text window, run it, and the script will select all the objects without materials.

Once selected, you can now work with those objects, such as moving them to another layer or linking them to another object with a material (to do this, shift-select an object with material, press CTRL L and make links to material). You can also move, transform, join, etc. all selected objects if you want, of course.

An object is only selected if it has not had any materials assigned to it ever. If you assign a material to an object and then delete the material link to that object, that object still retains a material index entry, even though the material has been disassociated with the object. I mention this because such objects are then not selected by this script.


# NO MATERIAL SELECTION SCRIPT
#
# BY: ROBERTT
# RELEASED: JANUARY 2006
# SCRIPT VERSION: 1.0
# TESTED ON BLENDER VERSIONS: 2.37A, 2.40
#
# WHAT THIS BLENDER PYTHON SCRIPT CAN DO:
#
# This script searches through all
# objects in your currently loaded
# .blend file and selects them if
# they do not have any materials
# linked to them.  Note: Objects
# that had materials removed still
# maintain a material index entry,
# so this script will not select
# those objects.  You can manually
# select additional objects by
# SHIFT-selecting them.  Once objects
# are selected, you may do with them
# whatever is necessary (move, place
# on another layer, transform, join,
# link to an object that has materials
# and so on.)
#
# USAGE TERMS:  USE THIS SCRIPT FREELY,
# AT YOUR OWN RISK, AND ADAPT AS YOU WISH.


import Blender
from Blender import *

objs = Blender.Object.Get()
print "
Searching for objects with no materials linked to them...
"

for o in objs:
	t = o.getType()
	if t == "Mesh" or t == "Curve" or t == "Surf" or t == "Text" or t == "MBall":
		m = o.getMaterials(1)
		if len(m) == 0:
			print o,  "has no materials.  Selecting object."
			o.select(1)

print "Done!"
Blender.Redraw()

Copy and paste the above code to a text file called nomatsel.py
or click here to download the script.

RobertT