I'm creating an addon where I create a new scene using ops.scene.new(type="FULL_COPY"). This creates copies of all objects and materials, which is good, because I want to keep the old scene unchanged.

Let's call the new scene Scene B. The problem is that, when I check which scene is active, it is indeed Scene B, but when I try to manipulate the newly created material with context.material, it is somehow the old material (from Scene A) that is still active. The weird thing is, I swear this worked yesterday. I've checked the code, but can't find anything that's changed. So, I guess I'm wondering why the new material isn't set as the active material, and how I can find the new material and only manipulate it. Or, if there is another better solution to copying a scene and only manipulating a copy... The code in question is attached below:

    def poll(cls, context):
        return context.material and context.scene.internal_props.nodes_loaded

    def execute(self, context):
        selected_scene = context.window.scene
        # Make a full copy of the current scene and only manipulate that one
            # Check if an old scene copy exists and delete it
            context.window.scene = bpy.data.scenes[SCENE_NAME]
        except KeyError as e:

        context.scene.name = SCENE_NAME

        objs = context.scene.objects
        material = context.material # Gets the old material :(
        render = context.scene.render
        all_props = context.scene.props
        nodes = material.node_tree.nodes
  • $\begingroup$ In what context are you running this? Properties panel? Shader editor? "material" is not a member of context in all spaces. $\endgroup$ – batFINGER Feb 4 '20 at 6:13
  • $\begingroup$ @batFINGER I'm running this from the Node Editor. I'm able to access the list of all materials, but I just don't know which one was created due to copying the scene. $\endgroup$ – Zorobay Feb 5 '20 at 1:10

Your Answer

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

Browse other questions tagged or ask your own question.