enzyme69 / blendersushi

Blender Sushi related scripts. Mostly about Sverchok, Geometry Nodes, Animation Nodes, and related Python scripts.
243 stars 33 forks source link

LIVENODING 1285 / CODING NODING Unique Materials and Texture #725

Open enzyme69 opened 4 years ago

enzyme69 commented 4 years ago
import bpy

sel = bpy.context.selected_objects
for ob in sel:
    mat = ob.active_material
    if mat:
         ob.active_material = mat.copy()
enzyme69 commented 4 years ago

import bpy

sel = bpy.context.selected_objects
for ob in sel:
    mat = ob.active_material
    if mat:
        ob.active_material = mat.copy()

        for ts in mat.texture_slots:
            try:
                ts.texture = ts.texture.copy()

                if ts.texture.image:
                    ts.texture.image = ts.texture.image.copy() 
            except:
                pass
enzyme69 commented 4 years ago

Original Thread from BA: https://blenderartists.org/t/make-materials-single-user-via-code/524068/5

enzyme69 commented 4 years ago
Screen Shot 2020-03-20 at 11 42 24 am

material_magic_004.blend.zip

enzyme69 commented 4 years ago

Additional idea from Benny Goaverts to try

image

enzyme69 commented 4 years ago

image

enzyme69 commented 4 years ago

Blender 2.82 example making single user material and image texture for sequence

import bpy
from random import randrange

# bpy.data.objects['Plane'].material_slots[0].material.node_tree.nodes['Image Texture'].image_user.frame_offset = frame

sel = bpy.context.selected_objects

for ob in sel:
    mat = ob.active_material
    if mat:
        # make single user for each material
        ob.active_material = mat.copy()

        # make single user texture for each material
        ob.active_material.node_tree.nodes['Image Texture'].image = ob.active_material.node_tree.nodes['Image Texture'].image.copy()

        # make cyclic
        ob.active_material.node_tree.nodes['Image Texture'].image_user.use_cyclic = True

        # randomize start frame
        randval = randrange(0, 101, 2)
        print(randval)
        ob.active_material.node_tree.nodes['Image Texture'].image_user.frame_start = randval