Dolmen Bretagne
Dolmen Bretagne

Reputation: 11

time.sleep() in Blender (Cycles) script

I am trying to change the color of a Cube with a delay between the two colors. It's seem not possible with

time.sleep(5)

When I run the script, it waits 5s and displays just the second color and the first is never used.

import bpy
import time
mat = bpy.data.materials.new("RED")
mat.diffuse_color = (0.8,0,0)
mesh = bpy.context.object.data
mesh.materials.append(mat)

time.sleep(5)

mat = bpy.data.materials.new("GREEN")
mat.diffuse_color = (0,0.8,0)
mesh = bpy.context.object.data
mesh.materials.clear()
mesh.materials.append(mat)

Certes il manquait "object", mais c n'est pas l'origine du phénomène, j'ai essayé les deux changments de couleurs séparément pas de problème, mais lors que je les assemble et les sépare par time.sleep(5) seul de vert est affiché ! Merci de ta réponse

Upvotes: 0

Views: 1959

Answers (1)

Dolmen Bretagne
Dolmen Bretagne

Reputation: 11

bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)

Upvotes: 1

Related Questions