# Copy all nodes from one material to another?

**URL:** <https://blenderartists.org/t/copy-all-nodes-from-one-material-to-another/1212351>\
**Category:** Python Support\
**Created:** [March 12, 2020, 3:49am UTC](https://blenderartists.org/t/copy-all-nodes-from-one-material-to-another/1212351 "2020-03-12T03:49:46Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Cirno](https://blenderartists.org/letter_avatar_proxy/v4/letter/c/7ba0ec/32.png) [@Cirno](https://blenderartists.org/u/Cirno)\
**Post date:** [March 12, 2020, 7:54am UTC](https://blenderartists.org/t/copy-all-nodes-from-one-material-to-another/1212351/2 "2020-03-12T07:54:29Z")

</div>

You can try to make a copy of the Source material, then replace all object slots that have Target material with the Copied material. Then delete Target material and rename Copied material to Target material

```auto
import bpy
context = bpy.context

# get materials
source_mat = bpy.data.materials["Source"]
target_mat = bpy.data.materials["Target"]

# make copy
copied_mat = source_mat.copy()

# replace material
for ob in context.scene.objects:
    if ob.type in ('MESH', 'CURVE'):
        if ob.data.materials:
            for slot in ob.material_slots:
                if slot.material.name == "Target":
                    slot.material = copied_mat

# delete initial target material
def purge_materials():
    """Remove materials with 0 users from scene."""
    for me in bpy.data.meshes:
        if not me.users:
            me.materials.clear()

    for material in bpy.data.materials:
        if not material.users:
            bpy.data.materials.remove(material)
            
purge_materials()

# rename copy 
copied_mat.name = "Target"

```

---

_[View the full topic](https://blenderartists.org/t/copy-all-nodes-from-one-material-to-another/1212351)._
