Skip to content

Commit

Permalink
Add callback to import operation for external scripting
Browse files Browse the repository at this point in the history
  • Loading branch information
TiberiumFusion committed Jun 2, 2021
1 parent c271634 commit c289f0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion io_scene_valvesource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions io_scene_valvesource/import_smd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit c289f0c

Please sign in to comment.