How to copy material in Blender Python?

Hi!

I have 2 things I would like to do with a Python script:

  1. Create a new material exactly the same as an existing material
  2. Assign all variables of one existing material to another existing material.

Obviously, if I find out how to do #2, I can also accomplish #1 in two steps.
The only way I can find to do it in Python is to explicitly copy every member variable of one material to another material, but that is not a good approach for several reasons. The most important reason being that the script would not be robust against additions to materials in future versions of Blender.

Can anyone help me? :slight_smile:

Best regards,
Mikkel

first. blender cvs therefor 2.43 has .copy() function for all libdata

mat2= mat1.copy()
assigning must be done in python - probably best you do your own function for that. - Maybe it could be added as a generic py function to BPyMaterial.py

Thanks!

That’s exactly what I was looking for!

Mikkel