0

Apparently in older versions of Blender, I could run code like this:

 bpy.data.scenes.frame_set(10)

When I try to run it in Blender 2.93, it requires that I include ['Scene'] when changing the frame.

enter image description here

Is there any way I can change the frame in Blender 2.93 regardless of which scene I am in?

Thanks!

Anson Savage
  • 3,392
  • 3
  • 31
  • 67
  • 2
    AFAIK bpy.data.scenes.frame_set(10) has never been available. One wonders if the answer here is simply bpy.context.scene.frame_set(20) to change frame on scene that has context. – batFINGER Aug 05 '21 at 13:53
  • @batFINGER Yeah, that was what I was looking for, thanks! – Anson Savage Aug 05 '21 at 23:21

2 Answers2

3

I can't find any global call to set the frame for all scenes in older API versions.

If you'd like to set the frame for all scenes, just iterate through the scenes in your blend and set the frame. Recommend use the python console to figure out:

>>> D.scenes
<bpy_collection[1], BlendDataScenes>

>>> for s in D.scenes: s.frame_set(23)

If you'd like to set the frame for a specific scene which is currently not the active one, get a reference of the actual scene using pythons get() and call Scene.frame_set() on that reference:

import bpy

scn = bpy.data.scenes.get("Scene") if scn: scn.frame_set(23)

In case you'd like to set the frame for multiple known scenes at once: I'd suggest create a list, set or tuple out of scene names and iterate through the items beforehand:

import bpy

for s in ('Scene', 'Scene.001', 'Scene.002'): scn = bpy.data.scenes.get(s) if scn: scn.frame_set(23)

brockmann
  • 12,613
  • 4
  • 50
  • 93
  • Thank you for the very thorough answer to my rather simple quesiton. batFINGER made a comment on my original question and what he suggested is what solved it for me. – Anson Savage Aug 05 '21 at 23:22
  • No problem. Based on your provided code (D.scenes) in combination with your question regardless of which scene I am in?, I did assume that you want to set the frame of a specific scene rather than the active scene. If your q is to set the frame for the current scene (C.scene), I voted to close as dupe to keep the site organized @AnsonSavage – brockmann Aug 06 '21 at 06:46
1

You have access to the scene frame_current property and you can also set it like below:

# for example if want to set 23 as current:
import bpy
bpy.context.scene.frame_current = 23

And if you want to set for all scenes you should do through a for loop:

import bpy
for sc in bpy.data.scenes:
    sc.frame_current = 23

  • Assigning a value to Scene.frame_current property won't update the scene, it moves the cursor in the timeline though. – brockmann Aug 05 '21 at 14:49
  • @brockmann but for me it updates an animated scene. either through context.scene or through for loop on data. it even updates all armatures and skinned meshes. – MohammadHossein Jamshidi Aug 05 '21 at 15:07
  • Yeah, I should have said: it won't update properly, e.g. try to render 2 frames using the render operator and set the current frame as you do here, you'll see that not all properties of the objects are updated properly: https://pasteall.org/Dfwn There are a lot of Q&As here as well dealing with this issue. – brockmann Aug 05 '21 at 17:09