diff --git a/bbp_ng/OP_MTL_fix_material.py b/bbp_ng/OP_MTL_fix_material.py index a117fbb..db14cc7 100644 --- a/bbp_ng/OP_MTL_fix_material.py +++ b/bbp_ng/OP_MTL_fix_material.py @@ -1,4 +1,5 @@ import bpy +from . import UTIL_functions from . import PROP_virtools_material, PROP_preferences class BBP_OT_fix_all_material(bpy.types.Operator): @@ -9,7 +10,9 @@ class BBP_OT_fix_all_material(bpy.types.Operator): @classmethod def poll(cls, context): - return PROP_preferences.get_raw_preferences().has_valid_blc_tex_folder() + # 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 diff --git a/bbp_ng/OP_OBJECT_legacy_align.py b/bbp_ng/OP_OBJECT_legacy_align.py index e11ef31..1f69ea9 100644 --- a/bbp_ng/OP_OBJECT_legacy_align.py +++ b/bbp_ng/OP_OBJECT_legacy_align.py @@ -43,25 +43,25 @@ class BBP_PG_legacy_align_history(bpy.types.PropertyGroup): align_x: bpy.props.BoolProperty( name = "X Position", default = False, - ) + ) # type: ignore align_y: bpy.props.BoolProperty( name = "Y Position", default = False, - ) + ) # type: ignore align_z: bpy.props.BoolProperty( name = "Z Position", default = False, - ) + ) # type: ignore current_align_mode: bpy.props.EnumProperty( name = "Current Object (Active Object)", items = _g_EnumHelper_AlignMode.generate_items(), default = _g_EnumHelper_AlignMode.to_selection(AlignMode.AxisCenter), - ) + ) # type: ignore target_align_mode: bpy.props.EnumProperty( name = "Target Objects (Other Objects)", items = _g_EnumHelper_AlignMode.generate_items(), default = _g_EnumHelper_AlignMode.to_selection(AlignMode.AxisCenter), - ) + ) # type: ignore #endregion @@ -109,21 +109,21 @@ def apply_flag_updated(self, context): options = {'HIDDEN', 'SKIP_SAVE'}, default = True, # default True value to make it as a "light" button, not a grey one. update = apply_flag_updated, - ) + ) # type: ignore recursive_hinder: bpy.props.BoolProperty( name = "Recursive Hinder", description = "An internal flag to prevent the loop calling to apply_flags's updator.", options = {'HIDDEN', 'SKIP_SAVE'}, default = False, - ) + ) # type: ignore align_history : bpy.props.CollectionProperty( name = "Historys", description = "Align history.", type = BBP_PG_legacy_align_history, - ) + ) # type: ignore @classmethod - def poll(self, context): + def poll(cls, context): return _check_align_requirement() def invoke(self, context, event): @@ -180,10 +180,13 @@ def draw(self, context): #region Core Functions def _check_align_requirement() -> bool: + # if we are not in object mode, do not do legacy align + if not UTIL_functions.is_in_object_mode(): + return False + # check current obj if bpy.context.active_object is None: return False - # check target obj with filter of current obj length = len(bpy.context.selected_objects) if bpy.context.active_object in bpy.context.selected_objects: diff --git a/bbp_ng/OP_OBJECT_virtools_group.py b/bbp_ng/OP_OBJECT_virtools_group.py index ca3d281..ba99afe 100644 --- a/bbp_ng/OP_OBJECT_virtools_group.py +++ b/bbp_ng/OP_OBJECT_virtools_group.py @@ -38,7 +38,11 @@ class BBP_OT_select_object_by_virtools_group(bpy.types.Operator, PROP_virtools_g description = "Selection mode", items = _g_EnumHelper_SelectMode.generate_items(), default = _g_EnumHelper_SelectMode.to_selection(SelectMode.Intersect) - ) + ) # type: ignore + + @classmethod + def poll(cls, context): + return UTIL_functions.is_in_object_mode() def invoke(self, context, event): wm = context.window_manager @@ -119,7 +123,7 @@ class BBP_OT_add_objects_virtools_group(bpy.types.Operator, PROP_virtools_group. bl_options = {'UNDO'} @classmethod - def poll(self, context): + def poll(cls, context): return len(bpy.context.selected_objects) != 0 def invoke(self, context, event): @@ -131,6 +135,7 @@ def execute(self, context): for obj in bpy.context.selected_objects: with PROP_virtools_group.VirtoolsGroupsHelper(obj) as gp: gp.add_group(group_name) + self.report({'INFO'}, "Grouping objects successfully.") return {'FINISHED'} def draw(self, context): @@ -143,7 +148,7 @@ class BBP_OT_rm_objects_virtools_group(bpy.types.Operator, PROP_virtools_group.S bl_options = {'UNDO'} @classmethod - def poll(self, context): + def poll(cls, context): return len(bpy.context.selected_objects) != 0 def invoke(self, context, event): @@ -155,6 +160,7 @@ def execute(self, context): for obj in bpy.context.selected_objects: with PROP_virtools_group.VirtoolsGroupsHelper(obj) as gp: gp.remove_group(group_name) + self.report({'INFO'}, "Ungrouping objects successfully.") return {'FINISHED'} def draw(self, context): @@ -167,7 +173,7 @@ class BBP_OT_clear_objects_virtools_group(bpy.types.Operator): bl_options = {'UNDO'} @classmethod - def poll(self, context): + def poll(cls, context): return len(bpy.context.selected_objects) != 0 def invoke(self, context, event): @@ -179,6 +185,7 @@ def execute(self, context): for obj in bpy.context.selected_objects: with PROP_virtools_group.VirtoolsGroupsHelper(obj) as gp: gp.clear_groups() + self.report({'INFO'}, "Clear objects groups successfully.") return {'FINISHED'} #endregion diff --git a/bbp_ng/UTIL_functions.py b/bbp_ng/UTIL_functions.py index 54a3d75..0dbcc57 100644 --- a/bbp_ng/UTIL_functions.py +++ b/bbp_ng/UTIL_functions.py @@ -80,6 +80,16 @@ def select_certain_objects(objs: tuple[bpy.types.Object, ...]) -> None: # select first object as active object bpy.context.view_layer.objects.active = objs[0] +def is_in_object_mode() -> bool: + # get active object from context + obj = bpy.context.active_object + + # if there is no active object, we think it is in object mode + if obj is None: return True + + # simply check active object mode + return obj.mode == 'OBJECT' + class EnumPropHelper(): """ These class contain all functions related to EnumProperty, including generating `items`,