context.scene not updating correctly #23135

Closed
opened 2010-08-01 11:07:32 +02:00 by Tom Edwards · 9 comments

%%%Consider this code:

bpy.context.screen.scene = bpy.data.scenes.new("My Scene")
print("Active scene is",bpy.context.scene)

  • When this is executed line-by-line from the console, the UI shows the new scene and context.scene becomes the scene we just created.

  • When it is executed from a script, the UI shows the new scene but context.scene does not change from its original value.

This is in r30581, and the problem has been reported as far back as 27070.%%%

%%%Consider this code: bpy.context.screen.scene = bpy.data.scenes.new("My Scene") print("Active scene is",bpy.context.scene) - When this is executed line-by-line from the console, the UI shows the new scene and context.scene becomes the scene we just created. - When it is executed from a script, the UI shows the new scene but context.scene does not change from its original value. This is in r30581, and the problem has been reported as far back as 27070.%%%
Author

Changed status to: 'Open'

Changed status to: 'Open'

%%%At the moment setting the current scene (or screen) is delayed until the next event loop, after everything has been handled. It would be useful if changing scenes was possible, but not sure if this should be considered a bug or current design limitation.%%%

%%%At the moment setting the current scene (or screen) is delayed until the next event loop, after everything has been handled. It would be useful if changing scenes was possible, but not sure if this should be considered a bug or current design limitation.%%%
Author

%%%Is there any way to have a script wait until the next event loop, or to force one to occur?%%%

%%%Is there any way to have a script wait until the next event loop, or to force one to occur?%%%
Member

%%%Tom: one of the next todos for Py API is to make scripts proper part of our event handling system, or with timers, or to attach to redraws. It's a known issue and will be resolved asap.%%%

%%%Tom: one of the next todos for Py API is to make scripts proper part of our event handling system, or with timers, or to attach to redraws. It's a known issue and will be resolved asap.%%%
Member

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'

Added subscriber: @solarlune

Added subscriber: @solarlune

Hello. No idea if this'll be heard, but I've been looking around for an answer and not getting anywhere.

I'm basically trying to do the same thing as Tom was - setting a scene, but bpy.context.scene doesn't update immediately. Is there a known way now to force another event loop or wait or something? Something to make bpy.context.scene update immediately?

Hello. No idea if this'll be heard, but I've been looking around for an answer and not getting anywhere. I'm basically trying to do the same thing as Tom was - setting a scene, but bpy.context.scene doesn't update immediately. Is there a known way now to force another event loop or wait or something? Something to make bpy.context.scene update immediately?
Author

Wow, a bug report from seven years ago! Since then I've discovered how to wait for the next event loop:

import bpy

def scene_update(scene):
	print(scene.name)
	bpy.app.handlers.scene_update_post.remove(scene_update)

def hook_scene_update(callback):
	bpy.app.handlers.scene_update_post.append(callback)
	
hook_scene_update(scene_update)
bpy.context.screen.scene = bpy.data.scenes[1]
Wow, a bug report from seven years ago! Since then I've discovered how to wait for the next event loop: ``` import bpy def scene_update(scene): print(scene.name) bpy.app.handlers.scene_update_post.remove(scene_update) def hook_scene_update(callback): bpy.app.handlers.scene_update_post.append(callback) hook_scene_update(scene_update) bpy.context.screen.scene = bpy.data.scenes[1] ```

Hmm, I don't think that'll work for my purposes - I'm doing something in a function that needs to execute immediately, so I dunno if I can wait over the course of a script execution...

Thanks for the answer, though! I'll see if I can make any headway. I'll let this stay dead, haha.

Hmm, I don't think that'll work for my purposes - I'm doing something in a function that needs to execute immediately, so I dunno if I can wait over the course of a script execution... Thanks for the answer, though! I'll see if I can make any headway. I'll let this stay dead, haha.
Sign in to join this conversation.
No Milestone
No project
No Assignees
4 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#23135
No description provided.