From 1bfae63fe316ebcfbc0a59288a065e0b8adbab2e Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Mon, 4 Apr 2022 22:04:11 +0800 Subject: [PATCH] preparing rename system development --- ballance_blender_plugin/BMFILE_export.py | 7 ++ ballance_blender_plugin/BMFILE_import.py | 7 ++ .../NAMES_rename_system.py | 95 +++++++++++++++++++ .../NAMES_rename_via_group.py | 35 ------- ballance_blender_plugin/__init__.py | 53 ++++++++--- 5 files changed, 149 insertions(+), 48 deletions(-) create mode 100644 ballance_blender_plugin/NAMES_rename_system.py delete mode 100644 ballance_blender_plugin/NAMES_rename_via_group.py diff --git a/ballance_blender_plugin/BMFILE_export.py b/ballance_blender_plugin/BMFILE_export.py index ca70723..dcfaff4 100644 --- a/ballance_blender_plugin/BMFILE_export.py +++ b/ballance_blender_plugin/BMFILE_export.py @@ -9,7 +9,14 @@ class BALLANCE_OT_export_bm(bpy.types.Operator, bpy_extras.io_utils.ExportHelper bl_idname = "ballance.export_bm" bl_label = 'Export BM' bl_options = {'PRESET'} + + # ExportHelper mixin class uses this filename_ext = ".bmx" + filter_glob: bpy.props.StringProperty( + default="*.bmx", + options={'HIDDEN'}, + maxlen=255, # Max internal buffer length, longer would be clamped. + ) export_mode: bpy.props.EnumProperty( name="Export mode", diff --git a/ballance_blender_plugin/BMFILE_import.py b/ballance_blender_plugin/BMFILE_import.py index fadc9f9..31694da 100644 --- a/ballance_blender_plugin/BMFILE_import.py +++ b/ballance_blender_plugin/BMFILE_import.py @@ -11,7 +11,14 @@ class BALLANCE_OT_import_bm(bpy.types.Operator, bpy_extras.io_utils.ImportHelper bl_idname = "ballance.import_bm" bl_label = "Import BM " bl_options = {'PRESET', 'UNDO'} + + # ImportHelper mixin class uses this filename_ext = ".bmx" + filter_glob: bpy.props.StringProperty( + default="*.bmx", + options={'HIDDEN'}, + maxlen=255, # Max internal buffer length, longer would be clamped. + ) texture_conflict_strategy: bpy.props.EnumProperty( name="Texture name conflict", diff --git a/ballance_blender_plugin/NAMES_rename_system.py b/ballance_blender_plugin/NAMES_rename_system.py new file mode 100644 index 0000000..fdbe1ae --- /dev/null +++ b/ballance_blender_plugin/NAMES_rename_system.py @@ -0,0 +1,95 @@ +import bpy +from . import UTILS_constants + +class rename_system_props(bpy.types.Operator): + name_standard: bpy.props.EnumProperty( + name="Name Standard", + description="Choose your prefered name standard", + items=( + ("YYC", "YYC Tools Chains", "YYC Tools Chains name standard."), + ("IMENGYU", "Imengyu Ballance", "Auto grouping name standard for Imengyu/Ballance") + ), + ) + + oper_source: bpy.props.EnumProperty( + name="Operation Target", + description="Rename target", + items=( + ("COLLECTION", "Selected Collections", ""), + ("OBJECTS", "Selected Objects", "") + ), + ) + + def invoke(self, context, event): + wm = context.window_manager + return wm.invoke_props_dialog(self) + + def draw(self, context): + layout = self.layout + layout.prop(self, "name_standard") + +class BALLANCE_OT_rename_via_group(rename_system_props): + """Rename object via Virtools groups""" + bl_idname = "ballance.rename_via_group" + bl_label = "Rename via Group" + bl_options = {'UNDO'} + + def execute(self, context): + return {'FINISHED'} + +class BALLANCE_OT_convert_name(rename_system_props): + """Convert name from one name standard to another one.""" + bl_idname = "ballance.convert_name" + bl_label = "Convert Name" + bl_options = {'UNDO'} + + def execute(self, context): + return {'FINISHED'} + +class BALLANCE_OT_auto_grouping(rename_system_props): + """Auto Grouping object according to specific name standard.""" + bl_idname = "ballance.auto_grouping" + bl_label = "Auto Grouping" + bl_options = {'UNDO'} + + def execute(self, context): + return {'FINISHED'} + +class ObjectBasicType(): + COMPONENT = 0 + +class NameInfoHelper(): + def __init__(_basic_type): + self.basic_type = _basic_type + + # extra field notes: + # + +def _get_selected_objects(oper_source): + if oper_source == 'COLLECTION': + for selected_item in bpy.context.selected_ids: + if selected_item.bl_rna.identifier == "Collection": + tuple(bpy.data.collections[item.name].objects) + elif oper_source == 'OBJECTS': + return bpy.context.selected_objects + else: + raise Exception("Unknow oper_source.") + +def _get_name_info_from_yyc_name(obj_name): + pass + +def _get_name_info_from_imengyu_name(obj_name): + pass + +def _get_name_info_from_group(obj_name): + pass + +def _set_for_yyc_name(name_info): + pass + +def _set_for_imengyu_name(name_info): + pass + +def _set_for_group(name_info): + pass + diff --git a/ballance_blender_plugin/NAMES_rename_via_group.py b/ballance_blender_plugin/NAMES_rename_via_group.py deleted file mode 100644 index 06e2bc1..0000000 --- a/ballance_blender_plugin/NAMES_rename_via_group.py +++ /dev/null @@ -1,35 +0,0 @@ -import bpy,bmesh -import mathutils -import bpy.types -from . import UTILS_functions - -class BALLANCE_OT_rename_via_group(bpy.types.Operator): - """Rename object via Virtools groups""" - bl_idname = "ballance.rename_via_group" - bl_label = "Rename via Group" - bl_options = {'UNDO'} - - name_standard: bpy.props.EnumProperty( - name="Name Standard", - description="Choose your prefered name standard", - items=( - ("YYC", "YYC Tools Chains", "YYC Tools Chains name standard."), - ("IMENGYU", "Imengyu Ballance", "Auto grouping name standard for Imengyu/Ballance") - ), - ) - - @classmethod - def poll(self, context): - return True - #return _check_rail_target() - - def invoke(self, context, event): - wm = context.window_manager - return wm.invoke_props_dialog(self) - - def execute(self, context): - return {'FINISHED'} - - def draw(self, context): - layout = self.layout - layout.prop(self, "name_standard") \ No newline at end of file diff --git a/ballance_blender_plugin/__init__.py b/ballance_blender_plugin/__init__.py index a0df65a..86ed204 100644 --- a/ballance_blender_plugin/__init__.py +++ b/ballance_blender_plugin/__init__.py @@ -13,7 +13,7 @@ bl_info={ # ============================================= # import system -import bpy,bpy_extras +import bpy, bpy_extras import bpy.utils.previews import os # import my code (with reload) @@ -49,22 +49,22 @@ if "bpy" in locals(): if "OBJS_add_rails" in locals(): importlib.reload(OBJS_add_rails) - if "NAMES_rename_via_group" in locals(): - importlib.reload(NAMES_rename_via_group) + if "NAMES_rename_system" in locals(): + importlib.reload(NAMES_rename_system) from . import UTILS_constants, UTILS_functions, UTILS_preferences from . import BMFILE_export, BMFILE_import from . import MODS_3dsmax_align, MODS_flatten_uv, MODS_rail_uv from . import OBJS_add_components, OBJS_add_floors, OBJS_add_rails -from . import NAMES_rename_via_group +from . import NAMES_rename_system # ============================================= # menu system class BALLANCE_MT_ThreeDViewerMenu(bpy.types.Menu): - """Ballance related 3D operator""" + """Ballance related 3D operators""" bl_idname = "BALLANCE_MT_ThreeDViewerMenu" - bl_label = "Ballance 3D" + bl_label = "Ballance" def draw(self, context): layout = self.layout @@ -73,6 +73,32 @@ class BALLANCE_MT_ThreeDViewerMenu(bpy.types.Menu): layout.operator(MODS_rail_uv.BALLANCE_OT_rail_uv.bl_idname) layout.operator(MODS_flatten_uv.BALLANCE_OT_flatten_uv.bl_idname) +class BALLANCE_MT_OutlinerMenu(bpy.types.Menu): + """Ballance rename operators""" + bl_idname = "BALLANCE_MT_OutlinerMenu" + bl_label = "Ballance" + + def draw(self, context): + layout = self.layout + + layout.label(text="For Collection") + oprt = layout.operator(NAMES_rename_system.BALLANCE_OT_rename_via_group.bl_idname) + oprt.oper_source = 'COLLECTION' + oprt = layout.operator(NAMES_rename_system.BALLANCE_OT_convert_name.bl_idname) + oprt.oper_source = 'COLLECTION' + oprt = layout.operator(NAMES_rename_system.BALLANCE_OT_auto_grouping.bl_idname) + oprt.oper_source = 'COLLECTION' + + layout.separator() + + layout.label(text="For Objects") + oprt = layout.operator(NAMES_rename_system.BALLANCE_OT_rename_via_group.bl_idname) + oprt.oper_source = 'OBJECTS' + oprt = layout.operator(NAMES_rename_system.BALLANCE_OT_convert_name.bl_idname) + oprt.oper_source = 'OBJECTS' + oprt = layout.operator(NAMES_rename_system.BALLANCE_OT_auto_grouping.bl_idname) + oprt.oper_source = 'OBJECTS' + class BALLANCE_MT_AddFloorMenu(bpy.types.Menu): """Add Ballance floor""" bl_idname = "BALLANCE_MT_AddFloorMenu" @@ -117,7 +143,10 @@ classes = ( OBJS_add_floors.BALLANCE_OT_add_floors, BALLANCE_MT_AddFloorMenu, - NAMES_rename_via_group.BALLANCE_OT_rename_via_group + NAMES_rename_system.BALLANCE_OT_rename_via_group, + NAMES_rename_system.BALLANCE_OT_convert_name, + NAMES_rename_system.BALLANCE_OT_auto_grouping, + BALLANCE_MT_OutlinerMenu ) def menu_func_bm_import(self, context): @@ -138,9 +167,8 @@ def menu_func_ballance_add(self, context): layout.menu(BALLANCE_MT_AddFloorMenu.bl_idname, icon='MESH_CUBE') def menu_func_ballance_rename(self, context): layout = self.layout - layout.separator() - layout.label(text="Ballance") - layout.operator(NAMES_rename_via_group.BALLANCE_OT_rename_via_group.bl_idname, text="Rename via Group") + layout.menu(BALLANCE_MT_OutlinerMenu.bl_idname) + def register(): # we need init all icon first @@ -161,15 +189,14 @@ def register(): bpy.types.VIEW3D_MT_editor_menus.prepend(menu_func_ballance_3d) bpy.types.VIEW3D_MT_add.append(menu_func_ballance_add) - bpy.types.OUTLINER_MT_collection.append(menu_func_ballance_rename) - + bpy.types.OUTLINER_HT_header.append(menu_func_ballance_rename) def unregister(): bpy.types.TOPBAR_MT_file_import.remove(menu_func_bm_import) bpy.types.TOPBAR_MT_file_export.remove(menu_func_bm_export) bpy.types.VIEW3D_MT_editor_menus.remove(menu_func_ballance_3d) bpy.types.VIEW3D_MT_add.remove(menu_func_ballance_add) - bpy.types.OUTLINER_MT_collection.remove(menu_func_ballance_rename) + bpy.types.OUTLINER_HT_header.remove(menu_func_ballance_rename) for cls in classes: bpy.utils.unregister_class(cls)