2
$\begingroup$

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.

$\endgroup$

1 Answer 1

2
$\begingroup$

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:
    tgt.data.materials.append(mat)
$\endgroup$
1
  • $\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$ Aug 18, 2015 at 15:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .