How to clean materials and texture copies?

Those Blender creates when you paste or append an object ? Contrary to 3d max for example Blender doesn’t ask you if you want to copy materials and textures or use same named existing ones. It just makes a single user copy . It quickly turns into a huge mess of mat.001 , mat.002 etc you can’t purge because each of them still on some object.

Is there any tool or addon that would allow to remap all the copies to original one without numbers?

Hi @Ivagr,

To copy one material to multiple meshes, select all the meshes that have the 'wrong ’ material and then the mesh that has the ‘correct’ material, then link/transfer data . . . Link Material . . .

which results in this:

Note: Only the first material slot is affected by this, so meshes with multiple materials assigned ( like the blue face of the cube ) are not affected.

You can then purge the unwanted materials if they no longer have a fake user or are assigned elsewhere.

Cheers,
Dj

Thank you but it doesn’t help much unfortunately . Since most of my objects have multi materials assigned even if in unused slots. it’s another issue of how to clean unused slots of many objects at once.
Besides manually selecting hundreds of objects is kind of tiresome especially if those materials copies are absolutely identical .

the only way I figured out is manually remapping materials in outliner but it’s still tedious as hell.

image

You can “force-unassign” material by Shift+click on the X button in the material settings.
That will remove selected material from ALL objects at once. When you save and re-open the file, the material will be gone.
Material

Select all the meshes. In the material drop down select the material you want . . .

then using the drop down arrow select copy material to selected, this will overwrite all materials with just that one material. It’s important that your active mesh ( the last one you pick) only has the one material on it which is what you want.

Dj.

You can try the following script:

import bpy

mats = bpy.data.materials

for mat in mats:
    (original, _, ext) = mat.name.rpartition(".")
    
    if ext.isnumeric() and mats.find(original) != -1:
        print("%s -> %s" %(mat.name, original))
        
        mat.user_remap(mats[original])
        mats.remove(mat)

Reference

1 Like

That doesn’t clean unused material slots in selected objects if same materials is used in some other objects

Your script is working for selected objects :slight_smile: Thank you very much. Could it work for the whole scene at once somehow? Including hidden objects?

I sometimes have hundreds of identical single user materials from appending or just copy/pasting objects scattered in hidden collections

I did some testing, like selecting nothing, hiding some objects and etc. It worked without any problem for the whole scene. The material names of the hidden objects are also in the same way like -x.001, x.002, x.003-, right? I can’t see any reason why it wouldn’t work :confused:

1 Like

I got an error on one of my scenes . But in another file it works perfectly :slight_smile: Thank you very much. It should be in default Blender distro

Blender’s material management is horrid compared to all other 3d applications.

For quick selection and/or assignments of materials, take a look at the Material Utilities addon that comes with Blender.
Also, for -some- more control on materials in the scene, have a look at Matalogue addon from Greg Zaal.

Hope it helps.

1 Like

Thanks for the link Rob, Sadly I kind of agree. I am wasting hours on complex scenes because of materials and textures IMO it should as you at least evry time you paste or append something if you want to add unique materials to your scene if same named ones already exist. Or have a preference setting for default behavior.

ps MAtalogue addon seems not working properly in 2.9

Could it be same kind of script that does the same with texture clones. For some uncertain reason I have gazillion of them in my blend files