-
Notifications
You must be signed in to change notification settings - Fork 6
/
main_blender_rpc.py
76 lines (58 loc) · 2.12 KB
/
main_blender_rpc.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from .pypresence import Presence
import bpy
from bpy.app.handlers import persistent
import time
import atexit
import sys
update_delay = 15.0
def main():
client_id = '638415602167447553'
global presence
presence = Presence(client_id)
global app_version
app_version = 'Blender ' + bpy.app.version_string
presence.connect()
bpy.app.handlers.load_post.append(start_timer)
bpy.app.handlers.render_init.append(render_started)
bpy.app.handlers.render_complete.append(render_ended)
bpy.app.handlers.render_cancel.append(render_ended)
atexit.register(close)
start_timer(None)
@persistent
def start_timer(dummy):
if bpy.app.timers.is_registered(update):
bpy.app.timers.unregister(update)
bpy.app.timers.register(update)
@persistent
def render_started(dummy):
if bpy.app.timers.is_registered(update):
bpy.app.timers.unregister(update)
start_time = int(round(time.time() * 1000))
presence.update(large_image='blender_icon', large_text=app_version, details=get_project_path(), state='RENDERING:', start=start_time)
@persistent
def render_ended(dummy):
bpy.app.timers.register(update)
presence.update(large_image='blender_icon', large_text=app_version, details=get_project_path(), state=get_project_info())
def get_project_path():
project_path = "None"
if bpy.data.is_saved:
if sys.platform == 'win32':
project_path = str(bpy.data.filepath).split('\\')[-1]
else:
project_path = str(bpy.data.filepath).split('/')[-1]
else:
project_path = 'Project Not Saved'
return project_path
def get_project_info():
stats = bpy.context.scene.statistics(bpy.context.view_layer)
stats_split = stats.split("|")
verts = stats_split[2].strip().split(":")[1]
faces = stats_split[3].strip().split(":")[1]
project_info = "Verts: " + verts + " | " + "Faces: " + faces
return project_info
def update():
presence.update(large_image='blender_icon', large_text=app_version, details=get_project_path(), state=get_project_info())
return update_delay
def close():
presence.clear()
presence.close()