import bpyimport time class ModalTimerOperator(bpy.types.Operator): """Operator which runs its self from a timer""" bl_idname = "wm.modal_timer_operator" bl_label = "Modal Timer Operator" limits = bpy.props.IntProperty(default=0) _timer = None def modal(self, context, event): if event.type in {'RIGHTMOUSE', 'ESC'} or self.limits > 30: self.limits = 0 self.cancel(context) return {'FINISHED'} if event.type == 'TIMER': if not ("Text" in bpy.data.objects): bpy.ops.object.text_add(location=(0, 0, 0), rotation=(0, 0, 0)) txt = bpy.data.objects['Text'] txt.data.body = 'Testing'+ time.ctime() #self.limits += 1 return {'PASS_THROUGH'} def execute(self, context): wm = context.window_manager self._timer = wm.event_timer_add(time_step=0.1, window=context.window) wm.modal_handler_add(self) return {'RUNNING_MODAL'} def cancel(self, context): wm = context.window_manager wm.event_timer_remove(self._timer) def register(): bpy.utils.register_class(ModalTimerOperator) def unregister(): bpy.utils.unregister_class(ModalTimerOperator) if __name__ == "__main__": register() # test call bpy.ops.wm.modal_timer_operator()
import bpyimport bgeimport timefor scene in bge.logic.getSceneList(): for obj in scene.objects: if obj.name=='Text': obj.text='Testing'+time.ctime()
import bpyimport bgeimport timefor scene in bge.logic.getSceneList(): for obj in scene.objects: if obj.name=='Text': obj.text='Testing'+time.ctime() if obj.name=='Cube': obj.worldPosition[0]+=0.1 obj.color[0]-=0.01
Есть код получает данные с сервера и выводит в консоль через print(data) мне нужно выводить данные на объект text но почему то выходит ошибка no module named bge и код перестает работать как исправить --------------------------------Этот код надо вставитьimport bpyimport bgeimport timefor scene in bge.logic.getSceneList(): for obj in scene.objects: if obj.name=='Text': obj.text='SSS'---------------------------------------------------------------------------------------------Вот сам код import bpyimport bgeimport timeimport socketfrom threading import Thread # This is the right package nameTCP_IP = '127.0.0.1'TCP_PORT = 5792BUFFER_SIZE = 1024s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.connect((TCP_IP, TCP_PORT))class UpdateThread(Thread): def __init__(self): self.stopped = False Thread.__init__(self) # Call the super construcor (Thread's one) def run(self): while not self.stopped: self.downloadValue() def downloadValue(self): data = s.recv(1024).decode() print (data)myThread = UpdateThread()myThread.start()for scene in bge.logic.getSceneList(): for obj in scene.objects: if obj.name == 'Text': obj.text = data--------------