Datablock Tool

That add-on add tools for fix some issues with the style that blender handle databloks for materials, textures, images and data (meshes). Today we don’t have a asset browser to handle append/ link/import in a nice way so is common to have issues like:

== The Problem ==

  1. If you import/append/CTRL+V (from another file) two times a single object, it will make 2 different materials and images. Some like material and material.001, image.png and image.001.png. what is insane in terms of scene management. In a ideal world blender would ask if you want new datablocks for that or use the one inside your scene. If you import 50 times you will have to edit manually 50 materials and will have 50 garbage images in your UV image editor.

== The Solution ==

  1. While we don’t have a asset browser, i wrote a python add-on that handle that kind of problem. Just select a group of objects and click in Object-> “Clean Materials Datablock”. it will look for the original material (that one without “.xxx” in his name) and apply to the selected objects.

  2. I wrote a tool to handle duplicated images in UV/Image Editor too, that can help if you use blender as a Asset Creator for game engines and need set the face texture. In this case the script will handle looking for each face of the selected object and apply the original texture ( The on without .xxx in his name)

== TODO ==

DONE
1) I will wrote yet a nice way to handle duplicated data (Meshes). Is so much common duplicate several times a object and after you see that you need edit all the objects manually. So we need to delete all objects, edit one and duplicate again… would be nice just to have that meshes turned in instances of the active one. Select all, select one to copy and click one button… That will be very useful to me at least

  1. There is one limitation in my script today. If you don’t have a original (the one without “.xxx” in his name) material or image the script just give up. would be nice if it apply the smaller, the “.001” for example. I will see a way to implement it soon

Usage Example:

I hope it can be usefull to you too. More sugestions are wellcome :rolleyes:

Download:
http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/3D_interaction/Datablock_Tools

2 Likes

I love you.

Thank you! I’ve spent probably 3 years grumbling about this, and finally the answer I’ve been looking for!

I suppose this is a good example for me - less complaining an more doing.

This would be a great as an option that is raised when assets are imported to a scene, as you say, but your solution is a very elegant solution to a very annoying problem!

I will try and follow your example and learn to use some python (or get get help from a friend who does).

Thanks again,

Rob.

Hi Vitorbabio,

Thks but why append x times the same object? One is sufficient and then intance them x times…no?

YOU MADE MY DAY! it was months since i’ve notice this problem with a bunch of books.

Will be nice record tutorial for tool for begiiners in Blender like me

Spirou4D: Thks but why append x times the same object? One is sufficient and then intance them x times…no?

When you append a object and after append another that share the same material/image/texture it create a new datablook too. That was a example but there is many cases in fact.

alan.zirpoli, MmAaXx :
Thanks guys =)

RoN43: Will be nice record tutorial for tool for begiiners in Blender like me

I will wrote the instructions to install and usage soon, but there’s not different of outers add-ons. just go in User Preferences/Add-ons e enable it in 3D View category =)

Update for Version 1.1
Better names and added the “Set Instance” function.

Problem:
If you duplicate a object or set instances as Single User there is no way to turn it instance without edit the data one by one.

Solution:
Set Instance: Add a nice way to handle duplicated data (Meshes) turning it in instances of the Active Object. Select all, select one to copy and click in Object-> DataBlock Tools -> Set Instance.

Added the script to my guithub repository

Link to information and download
http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/3D_interaction/Datablock_Tools

Usage Example:

Great tools/ Thanks

Searching more, i find that blender already have a function to set objects as instance of the active one. 3D View -> Objects -> Make Link -> Object Data. So i will remove it in the next update.

When you copy, instead of using Shift+D, use Alt+D. it will copy the object but the obdata will stay the same.
after that, if you want other material etc, all you need to do is to press the number that is near the material name to make duplication (with the .001 number…) and change the name.

Yaniv: When you make a instance (ALT+D) your material is a instance too. But when you CTRL+V a object from buffer it always make a copy not a instance. The same when you do a append . Try to CTRL+V objects one by one that share the same material in a .blend to another .blend and you see it will create a lot of materials. That’s not good for a scene management workflow. Some import formats have this issue too.

Thanks for the explanation.
But why not copy only the first object and Alt+D all other from him? is there any reason why I need to use Ctrl+V for all objects and then make them instances of the first?

If you have in the original file two objects that share a material/texture and Copy one and later other we get the same problem. Do not matter the way you look it, it’s a problem in the Design of Asset Management of Blender. Until we get a truly Asset Manager this problem will remains

Hi,

Thanks for this tool, as I said before, it saves me a lot of time, with materials where .001, .002 is added every time.

I import models of cars for some scenes, and they are named Car_Paint, Car_Tyres, Car_Rims etc, and it works well for removing the duplicate materials

Some items, like the license plates have difference colours, so I have materials names Car_Plates, Car_Plates_blue, Car_Plates_Yellow. In this case, clean materials datablocks addon, if it finds a material named Car_Plates_Yellow.001 changes the material to Car_Plates, not Car_Plates_Yellow. It a small thing, but it one material has a name which is a shortened version of another, it always goes to the shorter one, even if the longer name is an ‘orinigal’ material

Hope this is clear :).

Rob

Hey @vitorbalbio, do you think it would be possible for an addon to remove a data-block? For instance, remove a material, even if it has users, so those users will have no material in the slot this material used to reside in?

Some items, like the license plates have difference colours, so I have materials names Car_Plates, Car_Plates_blue, Car_Plates_Yellow. In this case, clean materials datablocks addon, if it finds a material named Car_Plates_Yellow.001 changes the material to Car_Plates, not Car_Plates_Yellow. It a small thing, but it one material has a name which is a shortened version of another, it always goes to the shorter one, even if the longer name is an ‘orinigal’ material

I will take a look on it, thanks to report :wink:

Hey @vitorbalbio, do you think it would be possible for an addon to remove a data-block? For instance, remove a material, even if it has users, so those users will have no material in the slot this material used to reside in?

One thing that we can do is force a “non used” state to the datablock and force a save + restart file in blender. That way we can exclude the datablock but since it save and restart the file, it will be a very dangerous and intrusive function.

Thank you Vitorbalbio,
I have been waiting forever something like this, though I see a possible issue, that is, when you do voluntarily a copy of a material, or a texture or a mesh, so to make some changes to them, blender gives to the new block the name ‘name.001’ and so forth; now it can happen that you don’t change this name after the duplication, so, because your script make distinctions relying on names, you risk to loose the modified datas.

EDIT: Of course we should be aware of the need of give more explicative names if we make use of this script, but it can happen anyway.

paolo

Yep, that can happen. It was coded for my own workflow and I usually use a nice name rule for materials. The problem that it fix is mostly about copy paste objects between blend files and apeend imports that cause duplicate in materials when it should not.