Affect only the materials in one scene but not others?

Okay, I’m trying to to write a script that duplicates a scene completely by using the new scene, full copy method and then turns all the materials in only the new scene shadeless.

Here is the code I have so far:


import bpy

class duplicatorOperator(bpy.types.Operator):
    """Duplicator Operator"""
    bl_idname = "object.duplicator_operator"
    bl_label = "Duplicator Operator"
    
    def execute(self, context):
        bpy.ops.scene.new(type='FULL_COPY')
        cloneScene1 = bpy.context.scene
        cloneScene1.name = 'clone1'
        for material in bpy.data.materials:
            material.use_shadeless = True
        return {'FINISHED'}
def add_object_button(self, context):
    self.layout.operator(duplicatorOperator.bl_idname, text=duplicatorOperator.__doc__, icon='PLUGIN')

def register():
    bpy.utils.register_class(duplicatorOperator)
    bpy.types.VIEW3D_MT_object.append(add_object_button)
if __name__ == "__main__":
    register()

So far it turns all the materials in the .blend file shadeless. But I need it to only turn the copied materials in the new scene shadeless. How do I get it to do that?

material are define for the file not a scene!

why not use matcap instead !
these are shadeless if I remember

another way would be to make the mat in the new scene as single
and then you an do whatever you want with it !

happy bl

Making the new materials shadeless in the first duplicate is just a small part of the big project. I’m likely to end up duplicating the scene several times to get several different arrangements of materials and textures, and there’s going to be any number of materials and textures in the original scene that will need to be changed in each duplicate. What exactly do you mean “make the mat in the new scene as single”?

If at first you can’t find a direct answer, see if anybody did something for stuff similar to it. A bit of research into things other than scenes (like layers and such) provided enough snippets of code to Frankenstein together something that seems to get the job done exactly as needed. However, I never learned best practices for using try checks…or best practices for programming in general really. So if somebody could tell me if doing this right (and not setting myself up for a really bizarre bug later on) I’d appreciate it.

The below code creates an operator in the object menu which, on activation, duplicates the current scene, sets the clone as the new current scene (as a feature of bpy.ops.scene.new), turns all the materials in or used by the clone scene (whichever terminology is better) to shadeless, switches back to the original Scene, duplicates it again, and sets the second clone to be the current scene so you can check if everything worked right.

import bpy
import colorsys

class duplicatorOperator(bpy.types.Operator):
    """Duplicator Operator"""
    bl_idname = "object.duplicator_operator"
    bl_label = "Duplicator Operator"
    
    def execute(self, context):
        bpy.ops.scene.new(type='FULL_COPY')
        cloneScene1 = bpy.context.scene
        cloneScene1.name = 'clone1'
        for ob in bpy.context.scene.objects:
            try:
                for mat in ob.data.materials:
                    mat.use_shadeless = True
                break
            except:
                #ignore
                break
        bpy.context.window.screen.scene = bpy.data.scenes['Scene']
        bpy.ops.scene.new(type='FULL_COPY')
        cloneScene2 = bpy.context.scene
        cloneScene2.name = 'clone2'

        return {'FINISHED'}
def add_object_button(self, context):
    self.layout.operator(duplicatorOperator.bl_idname, text=duplicatorOperator.__doc__, icon='PLUGIN')

def register():
    bpy.utils.register_class(duplicatorOperator)
    bpy.types.VIEW3D_MT_object.append(add_object_button)
if __name__ == "__main__":
    register()

So does this look okay?

why do you need to do a new clone scene ?
just change the mat in first scene to shadeless !

and is it in bl or cycles ?

how many scenes like that do you need and do you need to re define all mat on all objects with some new mat
can you elaborate

happy bl

don’t think you need to make a second scene !

not certain why shadeless don’t stick
probably because of the second scene copy

happy bl