BallanceBlenderHelper/bbp_ng/OP_MTL_fix_material.py
yyc12345 4ffe29654b feat: add translation context for operators and their properties.
- add translation context for operator, menu, panel and etc. and their associated properties.
- improve some name and description but not finished.
- move reset BME material function inside BMEMaterialsHelper.
- rename variable of collection visitor in BME adder operator for clear meaning.
- replace some message box to report in ballance elements reset operator, BME materials reset operator and rail UV operator
2025-01-11 21:36:11 +08:00

41 lines
1.4 KiB
Python

import bpy
from . import UTIL_functions
from . import PROP_virtools_material, PROP_preferences
class BBP_OT_fix_all_material(bpy.types.Operator):
"""Fix All Materials by Its Referred Ballance Texture Name."""
bl_idname = "bbp.fix_all_material"
bl_label = "Fix All Materials"
bl_options = {'UNDO'}
bl_translation_context = 'BBP_OT_fix_all_material'
@classmethod
def poll(cls, context):
# only enable this when plugin have a valid ballance texture folder
# and we are in object mode
return PROP_preferences.get_raw_preferences().has_valid_blc_tex_folder() and UTIL_functions.is_in_object_mode()
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_confirm(self, event)
def execute(self, context):
# do work and count
counter_all: int = 0
counter_suc: int = 0
for mtl in bpy.data.materials:
counter_all += 1
if PROP_virtools_material.fix_material(mtl):
PROP_virtools_material.apply_to_blender_material(mtl)
counter_suc += 1
# report and return
self.report({'INFO'}, f'Fix {counter_suc}/{counter_all} materials.')
return {'FINISHED'}
def register() -> None:
bpy.utils.register_class(BBP_OT_fix_all_material)
def unregister() -> None:
bpy.utils.unregister_class(BBP_OT_fix_all_material)