This repository was archived by the owner on Mar 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsniffer_timed.py
More file actions
61 lines (47 loc) · 1.75 KB
/
sniffer_timed.py
File metadata and controls
61 lines (47 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import bpy
import socket
class timed_sniffer(bpy.types.Operator):
"""timed sniffer"""
bl_idname = "wm.timed_sniffer"
bl_label = "Timed Sniffer"
_timer = None
def modal(self, context, event):
if event.type in {'RIGHTMOUSE', 'ESC'}:
self.cancel(context)
return {'CANCELLED'}
if event.type == 'TIMER':
# change theme color, silly!
watt = 100
UDP_IP = '' #listen to any address
UDP_PORT = 6454 #set Artnet port
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
data, addr = sock.recvfrom(4576)
if len(data) == 530:
#print("received message:", data)
values = [bytes for bytes in data[18:]]
#print(values)
for i in range(len(values)):
try:
obj = bpy.data.objects["%03d" % (i+1)].children[0]
'''REPLACE THIS LINE'''
except KeyError:
pass
return {'PASS_THROUGH'}
def execute(self, context):
wm = context.window_manager
self._timer = wm.event_timer_add(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(timed_sniffer)
def unregister():
bpy.utils.unregister_class(timed_sniffer)
if __name__ == "__main__":
register()
# test call
bpy.ops.wm.timed_sniffer()