You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Blender-TexTools/op_texture_reload_all.py

65 lines
1.7 KiB
Python

import bpy
import os
import bmesh
from mathutils import Vector
from collections import defaultdict
from math import pi
class op(bpy.types.Operator):
4 years ago
bl_idname = "uv.textools_texture_reload_all"
bl_label = "Reload Textures and remove unused Textures"
bl_description = "Reload all textures"
4 years ago
@classmethod
def poll(cls, context):
return True
4 years ago
def execute(self, context):
main(context)
return {'FINISHED'}
def main(context):
4 years ago
count_clear_mat = 0
count_clear_img = 0
count_reload = 0
4 years ago
for material in bpy.data.materials:
if not material.users:
count_clear_mat+=1
material.user_clear()
bpy.data.materials.remove(material)
4 years ago
# 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)
4 years ago
#Reload all File images
for img in bpy.data.images :
if img.source == 'FILE' :
count_reload+=1
img.reload()
4 years ago
# Refresh vieport texture
for window in bpy.context.window_manager.windows:
screen = window.screen
for area in screen.areas:
area.tag_redraw()
4 years ago
# 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)
4 years ago
if len(message) > 0:
bpy.ops.ui.textools_popup('INVOKE_DEFAULT', message=message)
bpy.utils.register_class(op)