3
$\begingroup$

I have a complex scene with CAD exported files and other meshes. There is a big amount of objects (> 200) and many of them are missing a material.

How do I select all the objects with no material so that I can apply one to them without affecting the other objects?

Shift+L + Material does not work because these objects do no share the same material.

$\endgroup$
  • $\begingroup$ Do the objects that have materials share the same material or do they all have separate ones (how many)? $\endgroup$ – Ray Mairlot Sep 15 '16 at 14:10
  • $\begingroup$ Separate materials, I currently have 6 different materials. $\endgroup$ – Victor Lamoine Sep 15 '16 at 14:11
  • $\begingroup$ Just as a note, I will only be notified of your comments if you '@' me, e.g. @RayMairlot. $\endgroup$ – Ray Mairlot Sep 15 '16 at 22:09
1
$\begingroup$

An automated way to do this is using python. What you do is deselecting all objects and then iterating through every object to see if it has a material. Then you select all the objects without a material.

#import the blender python module
import bpy

#deselect all objects
bpy.ops.object.select_all(action='DESELECT')

#looking through all objects
for obj in bpy.data.objects:
    #if the object is a mesh and not a lamp or camera etc.
    if obj.type == 'MESH':
        #looking through every material slot
        for slot in obj.material_slots:
            #if there's no material slot
            if slot.material == None:
                #select the object
                obj.select = True

You have to paste it into Blender's text editor and then hit Run Script at the bottom of the editor.

$\endgroup$
  • $\begingroup$ It works with if slot.material != None and bpy.ops.object.select_all(action='DESELECT') in the last line. Can you edit your answer to improve the script? (either make it work as is or use my workaround) $\endgroup$ – Victor Lamoine Sep 15 '16 at 14:55
  • $\begingroup$ But then your objects have materials assigned to them ;) This is what it looks like without a material applied: i.stack.imgur.com/Tisuk.png and then if slot.material == None would return True. You can edit the answer as well and put in the script that works for you, that's better than me editing in what I think is right. $\endgroup$ – palkonimo Sep 15 '16 at 15:00
  • $\begingroup$ You are right! I tested again and it works as is, I submitted an edit to fix the indentation. $\endgroup$ – Victor Lamoine Sep 15 '16 at 15:06
3
$\begingroup$

While you can select a material'd object and do Select > Linked > Material to select objects with the same material, I don't know how to automagically select non-material'd objects, so here's a work-around:

Select your material'd objects, them move them to another layer M, 2 (or whatever layer number you want). Once you have all the material'd objects on another layer, you'll be left with a layer full of non-material'd objects (and maybe a camera and some lights). At that point, you can A to select the remaining non-material'd objects.

$\endgroup$
  • $\begingroup$ Works with a reasonable amount of materials, clearly doesn't apply if the scene has 50+ materials :) $\endgroup$ – Victor Lamoine Sep 15 '16 at 14:56
  • $\begingroup$ True, but it's only six in this case. $\endgroup$ – Ron Proctor Sep 15 '16 at 15:12
0
$\begingroup$

I've tried the palkonimo's script in Blender 2.78 and it didn't work. So I've modified it a bit:

#import the blender python module
import bpy

#deselect all objects
bpy.ops.object.select_all(action='DESELECT')

#looking through all objects
for obj in bpy.data.objects:
    #if the object is a mesh and not a lamp or camera etc.
    if obj.type == 'MESH':
        slots = obj.material_slots.keys()
        # select the object if there's no material slot 
        # or if there're empty material slots
        obj.select = not ( slots and all( slot for slot in slots ) )
$\endgroup$
  • $\begingroup$ Note that your script is not doing the exact same job: in first case, it's selecting object that have material slots but with no material linked to it. And yours is selecting objects that have no material (slots) at all. So this is not matter of Blender version here. $\endgroup$ – lemon Apr 27 '17 at 11:24
  • $\begingroup$ @lemon ok, I've updated the script. I think 'missing material' most often means no material slots at all, but it's good idea to check for empty material slots as well. Thanks! $\endgroup$ – semyonfilippov Apr 28 '17 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.