19
$\begingroup$

How to know which object is using a material.

I know that a material is used 4 time -> picture under:number object material

I'm searching a solution with python and I'm blocked here :

bpy.data.materials['Y.000a'].users

But this function only return the number of users and not the name.

Of course the solutions, that I'm searching for, doesn't have to obligatory use python.

$\endgroup$
15
$\begingroup$

I wouldn't be surprised if there were a better solution, but here's what I use:

mat = bpy.context.object.active_material
objs = []
for obj in bpy.data.objects:
    for slot in obj.material_slots:
        if slot.material == mat:
            objs.append(obj)

Then objs will be a list of objects with the material mat. If you only know the material name and it's not the active material, simply replace the first line with:

mat = bpy.data.materials['material_name']

Note: This does not check if a material is assigned to any faces on the object, simply if the material is in one of the slots for that object.

$\endgroup$
  • 1
    $\begingroup$ You could also use objs = {}, and then in the if-statement: if not obj in objs: objs[obj]=[slot]; else: objs[obj].append(slot) to get a dictionary of the individual material slots, or add a counter to get the index (if required). $\endgroup$ – wchargin Nov 11 '13 at 16:47
28
$\begingroup$

The outliner is a great place to find things. Entering a string in search field located in the header not only finds items containing the string but highlights them for easy access. The search menu also offers choices for case sensitive and complete matches.

enter image description here

Many things can be found in the outliner - from objects and meshes to materials, textures, modifiers, vertex groups, constraints, bones and actions.

While image names used by blender internal textures can be searched, currently images used in nodes (internal or cycles) can't.

$\endgroup$
  • 1
    $\begingroup$ For a non-python solution, it's the best way I think. Thank you. $\endgroup$ – lucblender Nov 14 '13 at 10:18
  • $\begingroup$ I want to go over all of my materials and select (or get indices of) faces to which that specific material has been applied to. I haven't been able to find a good solution for doing that as of now. I would appreciate if you can take a look at my question here and see if you can offer a solution? $\endgroup$ – Amir Mar 17 '18 at 4:49
7
$\begingroup$

I have created a simple addon for this:

http://blenderartists.org/forum/showthread.php?317507-Addon-Simple-addon-to-display-material-relationships

enter image description hereExample screen

$\endgroup$
  • 2
    $\begingroup$ Please provide more than a link in your answer. Can you for instance, show a screenshot of your work? $\endgroup$ – Gunslinger Nov 13 '13 at 17:12
  • $\begingroup$ Link only answers are discouraged. (If the link goes, so does the answer) $\endgroup$ – gandalf3 Nov 14 '13 at 9:55
5
$\begingroup$

This isn't the best way, but for I'll post for completeness.


Another quick way is to select an object which you know has the material and press ShiftL> Material.

This will select all the objects which use the active material of the selected object.

$\endgroup$
  • $\begingroup$ Thanks in my case I use multiple scene and layer so it isn't very usefull. $\endgroup$ – lucblender Nov 14 '13 at 9:59
  • $\begingroup$ @lucblender It does have limitations, but it might be useful for a quick check in a one scene file. You could toggle all layers visible with the back-tick (`) key (The key below the escape key on most keyboards) $\endgroup$ – gandalf3 Nov 14 '13 at 10:03
  • $\begingroup$ For a quick check it's the best solutions I agree with that. $\endgroup$ – lucblender Nov 14 '13 at 10:16
1
$\begingroup$
MNAME = 'myMaterial'
obs = [o for o in bpy.data.objects
       if type(o.data) is bpy.types.Mesh
           and MNAME in o.data.materials]

or

obs = []
for o in bpy.data.objects:
    if isinstance(o.data, bpy.types.Mesh) and MNAME in o.data.materials:
        obs.append(o)
$\endgroup$

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.