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$
3
  • 1
    $\begingroup$ Do the objects that have materials share the same material or do they all have separate ones (how many)? $\endgroup$ Sep 15, 2016 at 14:10
  • $\begingroup$ Separate materials, I currently have 6 different materials. $\endgroup$ Sep 15, 2016 at 14:11
  • $\begingroup$ Just as a note, I will only be notified of your comments if you '@' me, e.g. @RayMairlot. $\endgroup$ Sep 15, 2016 at 22:09

4 Answers 4

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$
3
  • $\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$ Sep 15, 2016 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, 2016 at 15:00
  • $\begingroup$ You are right! I tested again and it works as is, I submitted an edit to fix the indentation. $\endgroup$ Sep 15, 2016 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$
2
  • $\begingroup$ Works with a reasonable amount of materials, clearly doesn't apply if the scene has 50+ materials :) $\endgroup$ Sep 15, 2016 at 14:56
  • $\begingroup$ True, but it's only six in this case. $\endgroup$ Sep 15, 2016 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$
2
  • 1
    $\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, 2017 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$ Apr 28, 2017 at 12:36
0
$\begingroup$
import bpy
bpy.ops.object.select_all(action='DESELECT')

for obj in bpy.context.view_layer.objects:
    if obj.type == 'MESH':
        for slot in obj.material_slots:
            if slot.material == None:
                obj.select_set(True)

This would be my version of the script working in 2.92

$\endgroup$
1
  • $\begingroup$ Hello and welcome, thanks for the post. This site is not a regular forum, answers should be substantial and thoroughly explain the solution and required workflow. One liners and short tips rarely make for a good answer, low quality posts may be removed at some point. Could you edit your post and provide some more details about the procedure and why it works? Perhaps add a few screenshots illustrating the workflow and final results. See How do I write a good answer? otherwise it may be converted into a comment. $\endgroup$ Mar 21, 2021 at 22:09

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.