Znatz
Znatz

Reputation: 1530

Blender frozen in python script?

I am new to both blender and python.

I tried to manipulate some properties of an object via python script in script console of blender.

What I don't understand is I can do it in this way.

bpy.data.object['Cube'].rotation_euler.x+=1

but when I put it in a loop.

import time
i=1
while i<100:
   i+=1
   bpy.data.object['Cube'].rotation_euler.x+=1
   print('run once')
   time.sleep(5)

Blender freezes without any output of 'run once'. Would someone please tell me what is wrong with this code.

Upvotes: 1

Views: 1607

Answers (1)

sambler
sambler

Reputation: 7079

Your script isn't freezing, blender just isn't getting a chance to update during the loop.

The time.sleep(5) command sleeps for 5 seconds, being run 100 times means the script takes 8 minutes to run at which stage blender updates it's interface again.

You may want to look at a modal operator - there are several samples within the python templates available in blender's text editor.

Upvotes: 2

Related Questions