I'm trying to script a baking in network and it works but now I'd like to print informations for the user (clients whose are connected for example)
I tried to print those informations in the 3D_view but it doesn't work because of the "context"
Code:
import bpy
import time
import blf
import bgl
from threading import Thread
class OperatorMaster(bpy.types.Operator):
bl_description = "Use this computer as master for baking"
bl_idname = "baking.master"
bl_label = "Operator Master"
def execute(self, context):
threadCatchClients = Thread(target = catchClients, args = [context]) #Create a thread for function catchClients
threadCatchClients.start()
[...] #Rest of code
def catchClients(context):
h = context.region.height
[...] #Some code
# Draw
if len(clients) != 0:
pos_y = h - 50
bgl.glColor4f(0.0, 1.0, 0.0, 0.7)
for c in clients:
# Draw text in this region.
pos_x = 20
pos_y -= 20
_handle = bpy.types.SpaceView3D.draw_handler_add(drawInformations, (c, pos_x, pos_y), 'WINDOW', 'POST_PIXEL')
context.area.tag_redraw()
else:
pos_x = 20
pos_y = h - 50
bgl.glColor4f(0.0, 1.0, 0.0, 0.7)
_handle = bpy.types.SpaceView3D.draw_handler_add(drawInformations, ('No clients for the moment', pos_x, pos_y), 'WINDOW', 'POST_PIXEL')
context.area.tag_redraw()
time.sleep(1)
while True:
[...] #Some code
if masterClosed:
break
else:
# Draw
if len(clients) != 0:
pos_y = h - 50
bgl.glColor4f(0.0, 1.0, 0.0, 0.7)
for c in clients:
# Draw text in this region.
pos_x = 20
pos_y -= 20
_handle = bpy.types.SpaceView3D.draw_handler_add(drawInformations, (c, pos_x, pos_y), 'WINDOW', 'POST_PIXEL')
context.area.tag_redraw()
else:
pos_x = 20
pos_y = h - 50
bgl.glColor4f(0.0, 1.0, 0.0, 0.7)
_handle = bpy.types.SpaceView3D.draw_handler_add(drawInformations, ('No clients for the moment', pos_x, pos_y), 'WINDOW', 'POST_PIXEL')
context.area.tag_redraw()
time.sleep(1)
And I have a ERROR:
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Program Files\Blender Foundation\Blender\2.79\python\lib\threading.py", line 914, in _bootstrap_inner
self.run()
File "C:\Program Files\Blender Foundation\Blender\2.79\python\lib\threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Admin\AppData\Roaming\Blender Foundation\Blender\2.79\scripts\addons\AxeonBakingTool\buttons.py", line 223, in catchClients
h = context.region.height
AttributeError: 'NoneType' object has no attribute 'height'
Is there someone who can help me?
Thanks a lot.
heightattrib andregionisNoneTyperight? First check whether you can access the actual context when calling your operator, then trycontext.area.height. – brockmann Aug 10 '18 at 09:35