1
$\begingroup$

I have a json file that is dynamically generated on a server. I'm currently using a python program to copy it locally. I have a script that can check the json file from blender, and change my object rotation, but I can't seem to make it work periodically (like, I'd like the script to run every 0.2 sec).

import json
import bpy
import time

def doit():
    with open('/somepath/blendjson.json') as data_file:    
        data = json.load(data_file)

    coordx = float(data['coordx'])/5
    coordy = float(data['coordy'])/5

    bpy.ops.transform.rotate(value=coordx, axis=(-1, -0, -0), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)

    bpy.ops.transform.rotate(value=coordy, axis=(-0, -1, -0), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)

while True:
    doit()
    time.sleep(0.2)

This script doesn't do anything in blender. When I kill it in the terminal, it throws an empty error, with nothing following it : "Error: Python script fail, look in the console for now..."

The issue here seems to be that time.sleep blocks the script. I can only see the results when I kill it.

I'm looking for an alternative to time.sleep that does not stop the script. I want to run the def every 200 ms, and see the result in real time.

$\endgroup$
  • $\begingroup$ The time.sleep(0.2) works with a simple print("test") instruction inside of the def. $\endgroup$ – Guillaume de Maleprade Mar 11 '18 at 12:18
  • $\begingroup$ So, did you look in the console? $\endgroup$ – Ray Mairlot Mar 11 '18 at 12:35
  • $\begingroup$ As I said, I looked into the terminal, where the error should appear, and it only told me to look in the console. I generally look there to look for the errors I get. $\endgroup$ – Guillaume de Maleprade Mar 11 '18 at 12:37
  • $\begingroup$ If you have more information to add, use the edit link below your question. $\endgroup$ – Ray Mairlot Mar 11 '18 at 12:43
  • 1
    $\begingroup$ There are some limitations doing this (about thread or timer), but you can use the approaches described in this answer blender.stackexchange.com/questions/64524/… $\endgroup$ – lemon Mar 11 '18 at 14:14

Your Answer

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

Browse other questions tagged or ask your own question.