1

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I didn't notice there is a modal operator in the template. I will try it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.