Maniphest T23135

context.scene not updating correctly
Closed, Archived

Assigned To
None
Authored By
Tom Edwards (artfunkel)
Aug 1 2010, 11:07 AM
Tags
  • BF Blender
  • Add-ons (BF-Blender)
Subscribers
Brecht Van Lommel (brecht)
carlos padial (carlospadial)
solarlune
Tom Edwards (artfunkel)
Ton Roosendaal (ton)

Description

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.

Event Timeline

Tom Edwards (artfunkel) edited a custom field.Aug 1 2010, 11:07 AM
Brecht Van Lommel (brecht) added a comment.Aug 4 2010, 11:44 AM

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.

Tom Edwards (artfunkel) added a comment.Aug 4 2010, 8:50 PM

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

Ton Roosendaal (ton) added a comment.Nov 11 2010, 8:26 PM

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.

Ton Roosendaal (ton) changed the task status from Unknown Status to Archived.Nov 11 2010, 8:26 PM
solarlune added a subscriber: solarlune.May 7 2017, 9:54 AM

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?

Tom Edwards (artfunkel) added a comment.May 7 2017, 10:35 AM

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]
solarlune added a comment.May 7 2017, 6:21 PM

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.