Can we activate a material_slot?

When joining different objects which have different materials, then separating them back, “all loose parts” style, the separated objects inherit of all the materials that the original objects had. So…

I’d like to remove a few specific material_slots to clan up that mess. In order to do that, using the 'material_slot_remove() method, each slot needs to be activated first. Search as I can, I haven’t been able to find out how to do that.

Please respond. Even if you’ve searched and didn’t find any method yourselves. At least I’ll know that it is not my brain which is turning to jelly.

Hopefully you will be able to help.

Thanks.

You could do it without the operators: Iterate through all the materials and unlink the unwanted ones.

I should have said that I found how to get rid of the unwanted materials for an object but that the slot itself, empty as it becomes, persists. This mess gets worse and worse as I repeat the ‘join/separate’ often and with different set of materials (long story). I suspect that it caused some export problems also.

Not exactly sure what you are doing, but I wrote an addon that goes thru the .blend file and creates a list of objects & materials assigned to each object & removes all materials, then it can re-assign the materials to the objects as they were before removing them.

It might be useful in your case, maybe not. You could use it to generate a list of materials assigned to each object (it will also remove materials in this step), then you could re-assign your materials, join the objects, do whatever to them, split them back out. Then a few tricky steps, save the text file it generates, remove materials again, reload saved text file, re-assign materials. Now all your objects will have the same materials you had before joining them…

Let me know if it would be useful, or exactly what you are trying to do and maybe I could modify it slightly for you…

Randy

edit: just read your last post, my script removes all material slots as well…

Modeling furniture: I made this addon that allows me to keep each part an object while letting me edit a selection of them as if they were one single object; leaving them as separated object is necessary for processing later into cutlists and bill of materials (BOM) later, also for substituting meshes to quickly change the style of elements)

, but I wrote an addon that goes thru the .blend file and creates a list of objects & materials assigned to each object & removes all materials, then it can re-assign the materials to the objects as they were before removing them.

I surely would like to compare notes. :slight_smile: I guess that the only change I’d make would be to limit the scope to one object at a time. Can you post that script ? :slight_smile:

save the text file it generates, remove materials again, reload saved text file, re-assign materials. Now all your objects will have the same materials you had before joining them…

I think that I could skip writing to a file since the work would be concentrated in a single function.

Let me know if it would be useful, or exactly what you are trying to do and maybe I could modify it slightly for you…

I could do that if you like, saving you some trouble and letting myself practice. :slight_smile:

Randy

edit: just read your last post, my script removes all material slots as well…

Better and better.

Thanks a bunch. :slight_smile:

I wrote this as a work around for a bug, but it didn’t work, the bug still persisted. The bug has been fixed since then. Kind of rough, but code is commented. Best way to see what this does is just a few simple mesh objects with simple materials and run the script & play with it. Install it as an addon. Works with 2.62 - not been tested with 2.63 - yet.

http://www.pasteall.org/31317

Feel free to ask any questions…

Randy

edit: it generates a text file in the text editor when it removes materials, then uses that text file to re-assign materials… I forgot that it is kind of incomplete in that it doesn’t inform the user that it generates the file…

Thanks Randy,

I have a bit of gardening to do first then I’ll get back with the results. :slight_smile: