9
$\begingroup$

I have made a script to generate a game asset in one click ( http://blenderartists.org/forum/showthread.php?383624-Dark-Blender-(Official-Thread)-optimized-for-sculpting-and-game-asset-creation ). My script save the textures by doing a render and import them with the .0001 number meaning frame 1. If the frame is changed my script is unable to find the texture.0001 so i want to set at the beginning of my Python script the frame to 1.

$\endgroup$
25
$\begingroup$

You can set the current frame by calling:

bpy.context.scene.frame_current = 1

bpy.context.scene.frame_set(1)

This will set the scene frame and updates all objects immediately, see the docs: https://docs.blender.org/api/current/bpy.types.Scene.html#bpy.types.Scene.frame_set


Related: How to stop Action Constraint giving different results when code is run in text editor vs python console?

Use the method frame_set(...) instead. It forces an immediate update of all objects in the scene, including animations (transformation matrices etc. will be calculated)

$\endgroup$
4
  • 4
    $\begingroup$ frame_current should only really be used as a read-only property. See: blender.stackexchange.com/a/6510/241 $\endgroup$ Jun 10 '16 at 23:35
  • $\begingroup$ I'm getting "python script fail" when i try this. DO i need write something else in my script? $\endgroup$ Dec 4 '17 at 14:03
  • $\begingroup$ @IvanKartofanov You need to import the bpy module. Just insert the line import bpy as the first line of the script. $\endgroup$
    – Leander
    Feb 21 '18 at 20:10
  • 1
    $\begingroup$ in Blender 2.83, this freezes the application, it crashes and shuts down. $\endgroup$
    – Mark
    Jun 27 '20 at 15:08
2
$\begingroup$

(For Blender 2.83+) In order to advance to the next frame, get the frame you're on currently and add one to it. Set that using frame_set:

currentFrame = bpy.data.scenes['Scene'].frame_current
bpy.data.scenes['Scene'].frame_set(currentFrame + 1)

Otherwise replace currentFrame + 1 with the frame number you want:

bpy.data.scenes['Scene'].frame_set(10)

This assumes you're in the default scene, 'Scene'. In 2.83...

bpy.context.scene.frame_set(10)

...still works for whatever scene you happen to be in.

$\endgroup$
2
  • 1
    $\begingroup$ Thanks for the answer. Could you explain what this does and add more details to your question. Don't just post some random code snippet, explain what it does. $\endgroup$ Jan 3 at 4:12
  • 1
    $\begingroup$ @DuarteFarrajotaRamos thanks, edited to add clarity and context $\endgroup$ Jan 3 at 4:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.