bpy.ops.scene.new fails to set context when called from properties panel #43057

Closed
opened 2014-12-29 17:19:11 +01:00 by Piotr Adamowicz · 8 comments

System Information
Windows 7 x64, GPU irrelevant

Blender Version
Broken: 2.73 53ec177
Worked: never?

Short description of error
bpy.ops.scene.new fails to set the context when called from the properties panel. Apparently users have been [struggling ]] with this for [ http://blenderartists.org/forum/showthread.php?204227-Select-Scene-from-Python | years .

Exact steps for others to reproduce the error

  1. Open attached .blend
  2. Run the script to register the Simple Operator
  3. Hover mouse over 3d view, run the Simple Object Operator from the spacebar search menu
  4. Notice the scene was duplicated and a box was added. This is what it's meant to do.
  5. Remove the new scene. Now, press the Scene Copy button in the Simple Object Operator panel in the render tab of the Properties panel.
  6. Notice the scene was duplicated, but the box object was added in the original scene. The box object is also empty and has no geometry.

Blend file: bpy_ops_scene_new_bug.blend

**System Information** Windows 7 x64, GPU irrelevant **Blender Version** Broken: 2.73 53ec177 Worked: never? **Short description of error** bpy.ops.scene.new fails to set the context when called from the properties panel. Apparently users have been [struggling ]] with [[ http:*blenderartists.org/forum/showthread.php?211778-Rendering-multiple-files-scenes-via-python-API&highlight= | this ]] for [[ http://blenderartists.org/forum/showthread.php?204227-Select-Scene-from-Python | years ](http:*blenderartists.org/forum/showthread.php?201501-set-active-scene-with-python). **Exact steps for others to reproduce the error** 1. Open attached .blend 2. Run the script to register the Simple Operator 3. Hover mouse over 3d view, run the Simple Object Operator from the spacebar search menu 4. Notice the scene was duplicated and a box was added. This is what it's meant to do. 5. Remove the new scene. Now, press the Scene Copy button in the Simple Object Operator panel in the render tab of the Properties panel. 6. Notice the scene was duplicated, but the box object was added in the original scene. The box object is also empty and has no geometry. Blend file: [bpy_ops_scene_new_bug.blend](https://archive.blender.org/developer/F134186/bpy_ops_scene_new_bug.blend)

Changed status to: 'Open'

Changed status to: 'Open'

Added subscriber: @MadMinstrel

Added subscriber: @MadMinstrel

Added subscribers: @ideasman42, @Sergey

Added subscribers: @ideasman42, @Sergey

@MadMinstrel, it is not recommended to use operators from other operators, especially if they're changing context. Using bpy.data is the way to go here.

@ideasman42, i'm not sure if the case above is supposed to work, and also not sure why there's a difference depending on how the operator was invoked. What's your opinion here?

@MadMinstrel, it is not recommended to use operators from other operators, especially if they're changing context. Using `bpy.data` is the way to go here. @ideasman42, i'm not sure if the case above is supposed to work, and also not sure why there's a difference depending on how the operator was invoked. What's your opinion here?

@Sergey In my particular case, I'm working on a baking addon. I have to prepare a scene before baking - merge/split objects, adjust UVs, modify shaders, run a compositor tree on the result once it's baked, etc. Lots of destructive stuff, which is why I'm doing it in a temporary scene. Since in the end I have to call bpy.ops.object.bake, and that relies on context, I don't think I can avoid setting it?

I'm not sure that this is supposed to work at all, but if not, it should at least generate an error, right? It'd be nice if it worked though. If it's not going to work, I'll have to move the bake button somewhere into the 3d View, and it sort of belongs in the Render tab.

@Sergey In my particular case, I'm working on a baking addon. I have to prepare a scene before baking - merge/split objects, adjust UVs, modify shaders, run a compositor tree on the result once it's baked, etc. Lots of destructive stuff, which is why I'm doing it in a temporary scene. Since in the end I have to call bpy.ops.object.bake, and that relies on context, I don't think I can avoid setting it? I'm not sure that this is supposed to work at all, but if not, it should at least generate an error, right? It'd be nice if it worked though. If it's not going to work, I'll have to move the bake button somewhere into the 3d View, and it sort of belongs in the Render tab.
Campbell Barton self-assigned this 2015-01-02 07:42:35 +01:00

This can probably be fixed, claiming.

This can probably be fixed, claiming.

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'

This is nearly the same bug as blender/blender#43976

The problem here is its not assured that the buttons context scene is matching the screen's scene.
In fact its possible to pin a scene and in that case you don't really want to use the pinned scene either.

So the fix is not to use the button context at all, use INVOKE_SCREEN / EXEC_SCREEN

This is nearly the same bug as blender/blender#43976 The problem here is its not assured that the buttons context scene is matching the screen's scene. In fact its possible to pin a scene and in that case you don't really want to use the pinned scene either. So the fix is not to use the button context at all, use `INVOKE_SCREEN` / `EXEC_SCREEN`
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#43057
No description provided.