0
$\begingroup$

I have a scene with many objects and many materials.

I'd like to create a script than substitute an existing material (let's call it "Mat2") with another existing material "Mat1", so that all the object that already had "Mat1" will keep it and all the objects having "Mat2" before, will take "Mat1" too.

I know I could:

  • loop through all objects with a for loop;
  • look if the material has "Mat2" and if true, assign "Mat1" to that object.

But It could be slow with a lot of objects, so I'm wondering: is there a way to directly merge the materials without looping all the objects?

$\endgroup$
4
  • $\begingroup$ What do you mean by 'merge'? If you mean you want to add a new material slot to an object if it already has "Mat2" in a material slot, then no, there is no way to do this without iterating through every object. The same is true if you want to replace "Mat2" with a new material. $\endgroup$ Commented Nov 13, 2021 at 20:21
  • $\begingroup$ Actually "merge" is not the right word... Sorry! :-) I'm not a native speaker and I didn't find an appropriate word. I mean this: In all the objects with "Mat2", that material slot will be replaced with "Mat1", so no new slots but replacing the material in the first and only slot (the objects and their materials are all managed by scripts and they have only one material slot) with another material. :-) $\endgroup$
    – mugnozzo
    Commented Nov 15, 2021 at 8:57
  • 1
    $\begingroup$ No apology necessary. Even native speakers don't always manage that with English's large and imprecise vocabulary. But no, it's not possible to do this without a loop over all objects. $\endgroup$ Commented Nov 15, 2021 at 14:45
  • $\begingroup$ Thanks! I'll manage it looping objects :-) $\endgroup$
    – mugnozzo
    Commented Nov 18, 2021 at 14:40

0

You must log in to answer this question.

Browse other questions tagged .