How can i copy all Material settings from one object to another using Python ?

In the materials settings drop down menu in the user interface i can copy/paste materials:

Copy Material ( which calls bpy.ops.material.copy() )
Paste Material ( which calls bpy.ops.material.paste() )

When i try to call bpy.ops.material.copy() from the python console i get a {'CANCELLED'} and the subsequent bpy.ops.material.paste() does not work.


Copy only the active Material:

tgt.active_material = src.active_material

Clean copy of all Material Slots from src to tgt:

tgt.data.materials.clear() # ensure the target material slots are clean
for mat in src.data.materials:
  • $\begingroup$ Is there an easy way to copy all properties of a material from another, apart from the texture in the texture slot ? I am trying to regroup textures of different materials into one materials'textures slots. I would like to copy all the materials properties, and then set the texture slots .The only way I can think of now is to copy in Python each property one by one, is that correct ? $\endgroup$ – Jonathan Chemla Aug 18 '15 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.