1
$\begingroup$

Blender 3.6.7LTS

When I trigger play animation I would like a script to change the background to a reddish colour To indicate that the animation is playing and when I stop the animation player it defaults to it's original colour.

I tried to chat GTP this, but to no avail.

My basic logic was

  1. Deafult = bpy.context.space_data.shading.background_type = 'THEME'

  2. When animation is playing change bpy.context.space_data.shading.background_type = 'VIEWPORT' and make it's colour bpy.context.space_data.shading.background_color = (0.0169089, 0.00796443, 0.00961567)

  3. When animation player has stopped, revert back to default.

Chat GTP can do the first 50%, it's fails knowing when the animation player has stopped, or my instructions are terrible.

I want this because sometimes the animation is playing in the background by mistake and it'll crunch my computer if I'm in weight mapping etc.

$\endgroup$
4
  • $\begingroup$ Or the simple version is, you change the shortcut for playing animations to something you do not click so easily by accident or remove the shortcut completely... just an idea because I know nothing about python scripting. That's why I filter out questions tagged with "python" or "scripting". Now the only thing that's left is people asking for python scripts would actually use matching tags for their questions ;-) $\endgroup$ Commented Mar 14 at 15:13
  • $\begingroup$ @GordonBrinkmann: time for you to learn it ;) you miss A LOT of possibilities. And since you know GN and shader nodes, you already have half the knowledge ;) $\endgroup$
    – Chris
    Commented Mar 14 at 16:08
  • $\begingroup$ @GordonBrinkmann I agree with the tagging, I will remember for the future. For the work around, in an ideal world their would be no innovation on the workaround if we were to never to have accidents. :D $\endgroup$ Commented Mar 14 at 16:23
  • 1
    $\begingroup$ @Chris The last months the only times I get to do something in Blender is when I try to solve problems from other users here on BSE. No time to learn something new 😆 But working with nodes helped me with ComfyUI. $\endgroup$ Commented Mar 14 at 20:06

1 Answer 1

1
$\begingroup$

UPDATE

version for Blender 3.6.7

bl_info = {
    "name": "Active Background",
    "author": "Blender.Fun",
    "version": (0, 1),
    "blender": (2, 80, 0),
    "location": "View3D",
    "description": "Changes background when animation is playing.",
    "warning": "",
    "doc_url": "",
    "category": "Themes",
}

import bpy



def start(scene):
    bpy.context.preferences.themes[0].view_3d.space.gradients.high_gradient = (1.0, 0.0, 0.0)
    
def stop(scene):
    bpy.context.preferences.themes[0].view_3d.space.gradients.high_gradient = (0.2, 0.2, 0.2)
    
    
   
def register(): 
    bpy.app.handlers.animation_playback_post.append(stop)
    bpy.app.handlers.animation_playback_pre.append(start)

    
def unregister():
    bpy.app.handlers.animation_playback_post.remove(stop)
    bpy.app.handlers.animation_playback_pre.remove(start)
 
if __name__ == "__main__":
    register()

works for Blender 4.20:

insert this into your text editor:

bl_info = {
    "name": "Active Background",
    "author": "Blender.Fun",
    "version": (0, 1),
    "blender": (2, 80, 0),
    "location": "View3D",
    "description": "Changes background when animation is playing.",
    "warning": "",
    "doc_url": "",
    "category": "Themes",
}

import bpy



def my_handler(scene):
    
    print("is in handler")
    
    if bpy.context.screen.is_animation_playing:
        bpy.context.preferences.themes[0].view_3d.space.gradients.high_gradient = (1.0, 0.0, 0.0)
    else:
        bpy.context.preferences.themes[0].view_3d.space.gradients.high_gradient = (0.2, 0.2, 0.2)
    
    
def register(): 
    bpy.app.handlers.animation_playback_post.append(my_handler)
    bpy.app.handlers.animation_playback_pre.append(my_handler)

    
def unregister():
    bpy.app.handlers.animation_playback_post.remove(my_handler)
    bpy.app.handlers.animation_playback_pre.remove(my_handler)
 
if __name__ == "__main__":
    register()

Run the script.

Enjoy :)

enter image description here

$\endgroup$
6
  • $\begingroup$ Don't do nothing for me, youtu.be/AIRBo31RyUw $\endgroup$ Commented Mar 14 at 18:02
  • $\begingroup$ ok, i am just downloading 3.67....give me 10 mins i think there was an API change $\endgroup$
    – Chris
    Commented Mar 14 at 18:15
  • 1
    $\begingroup$ i updated my answer $\endgroup$
    – Chris
    Commented Mar 14 at 18:28
  • $\begingroup$ Thanks dude! I owe you one. Internet hug! $\endgroup$ Commented Mar 14 at 19:04
  • $\begingroup$ Any idea why it's not persistent on re-loading blender? $\endgroup$ Commented Mar 14 at 19:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .