forked from samytichadou/Auto_Reload_Blender_addon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
74 lines (65 loc) · 2.64 KB
/
functions.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
import bpy
import os
import time
from bpy.app.handlers import persistent
def reload_images():
#reload all images
for i in bpy.data.images:
i.reload()
#update viewers
wman=bpy.data.window_managers['WinMan']
for win in wman.windows:
scr = win.screen
for area in win.screen.areas:
area.tag_redraw()
#redraw if viewport in rendered mode
region = [region for region in area.regions if region.type == 'WINDOW']
if area.type=='VIEW_3D':
for space in area.spaces: # iterate through spaces in current VIEW_3D area
#print(space.shading.type)
if False and space.type == 'VIEW_3D' and space.shading.type in ['MATERIAL','RENDERED']: # check if space is a 3D view
override = {'window':win,
'screen':scr,
'area' :area,
'region':region,
'scene' :bpy.context.scene,
'blend_data' :bpy.context.blend_data
}
bpy.ops.view3d.toggle_render(override)
bpy.ops.view3d.toggle_render(override)
elif area.type=='IMAGE_EDITOR':
for space in area.spaces:
if space.type == 'IMAGE_EDITOR':
s=space
override = {'window':win,
'screen':scr,
'area' :area,
'region':region,
'scene' :bpy.context.scene,
'blend_data' :bpy.context.blend_data,
'edit_image' :s.image
}
bpy.ops.image.reload(override)
elif area.type=='NODE_EDITOR':
for space in area.spaces:
if space.type == 'NODE_EDITOR':
if space.show_backdrop == True:
space.show_backdrop = True
return{"FINISHED"}
def get_modification_times():
for i in bpy.data.images:
try:
path=os.path.abspath(bpy.path.abspath(i.filepath))
i.modification_time=str(os.path.getmtime(path))
except FileNotFoundError:
i.modification_time="missing"
return{"FINISHED"}
@persistent
def reload_startup(scene):
for i in bpy.data.images:
try:
path=os.path.abspath(bpy.path.abspath(i.filepath))
i.modification_time=str(os.path.getmtime(path))
except FileNotFoundError:
i.modification_time="missing"
print("Auto Reload Images --- All images modification time updated")