I am trying to connect a physical robot arm with its digital replica using blender I am able to communicate between the two using MQTT but the changes in blender are reflected only when the python script associated with it completes execution but I want the change to be seen as soon as the value is received by blender, ie, updating the viewport before complete execution. I have tried using: bpy.ops.wm.redraw_timer and bpy.scene.update() but this doesn't work in my case, I even tried the solution given in Update viewport while running script but it doesn't really help me. Here is my code snippet, can someone please tell what is wrong and how to update the viewport? PS- Blender version is 2.8.0 Thank you in advance:) import bpy import json import paho.mqtt.client as mqtt from math import radians from math import pi # It's considered bad practice to import everything from a library, especially when you're not using any (or just a few) of its function
import mathutils
from mathutils import Euler
def changes(a,b,c):
Shouldercord1=pi*(92.3/180)
Shouldercord2=pi*(a/180) #to be changed
Shouldercord3=pi*(62.2/180)
obj=bpy.data.objects['Arm 01']
obj.rotation_euler = Euler((Shouldercord1,Shouldercord2 ,Shouldercord3) , 'XYZ')
Waistcord1=pi*(-269/180)
Waistcord2=pi*(0.642/180)
Waistcord3=pi*(b/180) #to be changed
obj2=bpy.data.objects['Waist']
obj2.rotation_euler = Euler((Waistcord1,Waistcord2 ,Waistcord3) , 'XYZ')
Armcord1=pi*(261/180)
Armcord2=pi*(c/180) #to be changed
Armcord3=pi*(-128/180)
obj3=bpy.data.objects['Arm 02 v3']
obj3.rotation_euler = Euler((Armcord1,Armcord2 ,Armcord3) , 'XYZ')
def on_connect(client, userdata, flags, rc):
print("\tMQTT Server Connected code "+str(rc))
client.subscribe('blender/test')
def on_message(client, userdata, msg):
message = (msg.payload)
#print(message)
#sys.exit(0)
result=json.loads(message)
a= result["a"]
b= result["b"]
c= result["c"]
changes(a,b,c)
client = mqtt.Client()
client.on_connect = on_connect
client.username_pw_set("xxxx","xxxx")
client.connect("xxxx", 1883, xx)
client.on_message = on_message
client.loop_forever()