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:
@classmethod 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 try: # Check if an old scene copy exists and delete it context.window.scene = bpy.data.scenes[SCENE_NAME] ops.object.select_all() ops.object.delete() bpy.ops.scene.delete() except KeyError as e: pass ops.scene.new(type="FULL_COPY") 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