From 019a5eba0f9f1479a643db68be1a9e2d95fd580b Mon Sep 17 00:00:00 2001 From: Menithal Date: Sat, 17 Mar 2018 22:38:13 +0200 Subject: [PATCH] 0.6.4: Added Error Messages --- __init__.py | 4 +++- hifi_armature_repose.py | 12 +++++------ hifi_armature_ui.py | 47 ++++++++++++++++++++++++++++++++++++----- hifi_json_writer.py | 33 ++++++++++++++++++++++++++++- 4 files changed, 83 insertions(+), 13 deletions(-) diff --git a/__init__.py b/__init__.py index 388bceb..774e947 100644 --- a/__init__.py +++ b/__init__.py @@ -20,7 +20,7 @@ bl_info = { "name": "HiFi Blender Add-on", "author": "Matti 'Menithal' Lahtinen", - "version": (0,6,3), + "version": (0,6,4), "blender": (2,7,7), "location": "File > Import-Export, Materials, Armature", "description": "Blender tools to allow for easier Content creation for High Fidelity", @@ -79,6 +79,7 @@ def menu_func_export(self,context): def register(): bpy.utils.register_class(HifiJsonOperator) bpy.utils.register_class(HifiJsonWriter) + bpy.utils.register_class(HifiATPReminderOperator) bpy.types.INFO_MT_file_import.append(menu_func_import) bpy.types.INFO_MT_file_export.append(menu_func_export) material_ui_register() @@ -87,6 +88,7 @@ def register(): def unregister(): bpy.utils.unregister_class(HifiJsonOperator) bpy.utils.unregister_class(HifiJsonWriter) + bpy.utils.unregister_class(HifiATPReminderOperator) bpy.types.INFO_MT_file_import.remove(menu_func_import) bpy.types.INFO_MT_file_export.remove(menu_func_export) material_ui_unregister() diff --git a/hifi_armature_repose.py b/hifi_armature_repose.py index 0fb52fe..fe6879b 100644 --- a/hifi_armature_repose.py +++ b/hifi_armature_repose.py @@ -4,10 +4,8 @@ from math import pi from .hifi_armature_data import structure as base_armature - # This is unit tested to be correct. - def correct_scale_rotation(obj, rotation): current_context = bpy.context.area.type bpy.context.area.type = 'VIEW_3D' @@ -63,7 +61,7 @@ def navigate_armature(data, current_rest_node, world_matrix, parent, parent_node def retarget_armature(options): armature = bpy.context.object - if armature.type == "ARMATURE": + if armature != None and armature.type == "ARMATURE": # Center Children First bpy.ops.object.mode_set(mode='OBJECT') @@ -124,7 +122,9 @@ def retarget_armature(options): bpy.ops.object.mode_set(mode='POSE') print("Apply Armature") bpy.ops.pose.armature_apply() - - - bpy.ops.object.mode_set(mode='OBJECT') + + else: + #Judas proofing: + print("No Armature, select, throw an exception") + raise Exception("You must select an armature to continue") diff --git a/hifi_armature_ui.py b/hifi_armature_ui.py index a06127d..0fea501 100644 --- a/hifi_armature_ui.py +++ b/hifi_armature_ui.py @@ -142,28 +142,64 @@ def execute(self, context): class HifiArmatureRetargetPoseOperator(bpy.types.Operator): bl_idname = "armature_toolset_retarget.hifi" - bl_label = "Retarget Avatar Pose / Fix Avatar" + bl_label = "Retarget Avatar Pose / Fix Avatar Scale / Rotation" bl_space_type = "VIEW_3D" bl_region_type = "TOOLS" bl_category = "High Fidelity" def execute(self, context): - retarget_armature({'apply': True}) + try: + retarget_armature({'apply': True}) + except Exception: + bpy.ops.hifi_error.armature_not_selected('INVOKE_DEFAULT') + return {'CANCELLED'} + return {'FINISHED'} class HifiArmaturePoseOperator(bpy.types.Operator): bl_idname = "armature_toolset_pose.hifi" - bl_label = "Test with Hifi Avatar rest Pose" + bl_label = "Test Avatar Rest Pose" bl_space_type = "VIEW_3D" bl_region_type = "TOOLS" bl_category = "High Fidelity" def execute(self, context): - retarget_armature({'apply': False}) + try: + retarget_armature({'apply': False}) + except Exception: + bpy.ops.hifi_error.armature_not_selected('INVOKE_DEFAULT') + return {'CANCELLED'} + return {'FINISHED'} + + +class HifiReminderOperator(bpy.types.Operator): + bl_idname = "hifi_error.armature_not_selected" + bl_label = "You must select an armature first prior to pressing the button" + bl_options = {'REGISTER', 'INTERNAL'} + + @classmethod + def poll(cls, context): + return True + + def invoke(self, context, even): + print("Invoked") + wm = context.window_manager + return wm.invoke_popup(self, width=400, height=200) + + def execute(self, context): + return {'FINISHED'} + + def draw(self, context): + layout = self.layout + + row = layout.row() + row.label(text="Warning:", icon="ERROR") + row = layout.row() + row.label(self.bl_label) @@ -171,7 +207,8 @@ def execute(self, context): HifiArmaturePanel, HifiArmatureCreateOperator, HifiArmatureRetargetPoseOperator, - HifiArmaturePoseOperator + HifiArmaturePoseOperator, + HifiReminderOperator ] def armature_create_menu_func(self,context): diff --git a/hifi_json_writer.py b/hifi_json_writer.py index 2af6735..f2a80bc 100644 --- a/hifi_json_writer.py +++ b/hifi_json_writer.py @@ -391,7 +391,9 @@ def execute(self, context): raise Exception("filepath not set") if not self.url_override and not self.atp: - raise Exception("You must Use ATP or Set the Marketplace / base URL to make sure that the content can be reached after you upload it. ATP currently not supported") + bpy.ops.hifi_error.atp_or_override_not_in_use('INVOKE_DEFAULT') + return {'CANCELLED'} + # raise Exception("You must Use ATP or Set the Marketplace / base URL to make sure that the content can be reached after you upload it. ATP currently not supported") current_scene = bpy.context.scene read_scene = current_scene @@ -457,3 +459,32 @@ def execute(self, context): return {'FINISHED'} +class HifiATPReminderOperator(bpy.types.Operator): + bl_idname = "hifi_error.atp_or_override_not_in_use" + bl_label = "You must either select ATP export or override a baseURL for your host (be it marketplace or your own)" + bl_options = {'REGISTER', 'INTERNAL'} + + @classmethod + def poll(cls, context): + return True + + def invoke(self, context, even): + print("Invoked") + wm = context.window_manager + return wm.invoke_popup(self, width=400, height=300) + + def execute(self, context): + return {'FINISHED'} + + def draw(self, context): + layout = self.layout + + row = layout.row() + row.label(text="Warning:", icon="ERROR") + row = layout.row() + row.label("You must either select ATP export ") + row = layout.row() + row.label(" or override a baseURL for your host") + row = layout.row() + row.label(" (be it marketplace or your own)") +