forked from drewcassidy/TexTools-Blender
-
Notifications
You must be signed in to change notification settings - Fork 1
/
op_texture_reload_all.py
64 lines (52 loc) · 1.73 KB
/
op_texture_reload_all.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
import bpy
import os
import bmesh
from mathutils import Vector
from collections import defaultdict
from math import pi
class op(bpy.types.Operator):
bl_idname = "uv.textools_texture_reload_all"
bl_label = "Reload Textures and remove unused Textures"
bl_description = "Reload all textures"
@classmethod
def poll(cls, context):
return True
def execute(self, context):
main(context)
return {'FINISHED'}
def main(context):
count_clear_mat = 0
count_clear_img = 0
count_reload = 0
for material in bpy.data.materials:
if not material.users:
count_clear_mat+=1
material.user_clear()
bpy.data.materials.remove(material)
# Clean up unused images
for image in bpy.data.images:
if not image.users:
count_clear_img+=1
image.user_clear()
bpy.data.images.remove(image)
#Reload all File images
for img in bpy.data.images :
if img.source == 'FILE' :
count_reload+=1
img.reload()
# Refresh vieport texture
for window in bpy.context.window_manager.windows:
screen = window.screen
for area in screen.areas:
area.tag_redraw()
# Show popup on cleared & reloaded items
message = ""
if count_reload > 0:
message+="{}x reloaded. ".format(count_reload)
if count_clear_mat > 0:
message+="{}x mat cleared. ".format(count_clear_mat)
if count_clear_img > 0:
message+="{}x img cleared.".format(count_clear_img)
if len(message) > 0:
bpy.ops.ui.textools_popup('INVOKE_DEFAULT', message=message)
bpy.utils.register_class(op)