From c289f0cac9637f7214e30ecb85f4d493e6c6b209 Mon Sep 17 00:00:00 2001 From: TiberiumFusion <6332277+TiberiumFusion@users.noreply.github.com> Date: Wed, 2 Jun 2021 18:13:51 -0400 Subject: [PATCH] Add callback to import operation for external scripting --- io_scene_valvesource/__init__.py | 2 +- io_scene_valvesource/import_smd.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/io_scene_valvesource/__init__.py b/io_scene_valvesource/__init__.py index d31d2ff..9cdaf58 100644 --- a/io_scene_valvesource/__init__.py +++ b/io_scene_valvesource/__init__.py @@ -21,7 +21,7 @@ bl_info = { "name": "Blender Source Tools (BST-Fix+ for 2.79)", "author": "Tom Edwards (translators: Grigory Revzin), modified by TF", - "version": (2, 10, 2, 999, 5), + "version": (2, 10, 2, 999, 6), "blender": (2, 74, 0), "category": "Import-Export", "location": "File > Import/Export, Scene properties", diff --git a/io_scene_valvesource/import_smd.py b/io_scene_valvesource/import_smd.py index 4bb62a0..287dc4c 100644 --- a/io_scene_valvesource/import_smd.py +++ b/io_scene_valvesource/import_smd.py @@ -62,6 +62,10 @@ class SmdImporter(bpy.types.Operator, Logger): mdlOriginPickOpts = (("DEFAULT", "Default", "Set armature origin to $origin; will fall back to 0,0,0 if not available."), ("BBOX", "From Bounding Box", "Set armature origin to the median boint of the MDL's bounding box. Requires $bbox to exist in the QC; will fall back to 0,0,0 if not available.")) mdlOriginPick = EnumProperty(name=get_id("importerx_mdloriginpick"), description=get_id("importerx_mdloriginpick_tooltip"), items=mdlOriginPickOpts, default="DEFAULT") + # Script access only properties + callback_operation = StringProperty(default="_", options={'HIDDEN'}) # Short name (e.g. "object.some_operation") of an Operation to run immediately after the import has finished + + def execute(self, context): pre_obs = set(bpy.context.scene.objects) @@ -128,6 +132,17 @@ def execute(self, context): context.user_preferences.edit.use_enter_edit_mode = pre_eem self.append = pre_append + # Callback operation + # Method to resolve operator class short string name to actual operator object courtesy of: https://blender.stackexchange.com/a/23955/68041 + def get_operator_failsafe(idname): + op = bpy.ops + for attr in idname.split("."): + if attr not in dir(op): + return lambda: None + op = getattr(op, attr) + return op + get_operator_failsafe(self.callback_operation)() + return {'FINISHED'} def invoke(self, context, event):