From 9b3301acb6d2351dff6d0f8400d5dc3a21336d25 Mon Sep 17 00:00:00 2001 From: vanous Date: Mon, 22 Jul 2024 18:34:16 +0200 Subject: [PATCH] Ensure app compatiblity for In/Out operations --- in_gdtf.py | 45 +++++++++++++++++++++++++++---------- in_out_mvr.py | 62 +++++++++++++++++++++++++++++++++++---------------- 2 files changed, 76 insertions(+), 31 deletions(-) diff --git a/in_gdtf.py b/in_gdtf.py index a99a6d4d..83d06bd7 100644 --- a/in_gdtf.py +++ b/in_gdtf.py @@ -2,9 +2,14 @@ import shutil import os import traceback -from bpy_extras.io_utils import ( - ImportHelper, -) + +from bpy_extras.io_utils import ImportHelper + +from threading import Timer + +if bpy.app.version >= (4, 2): + from bpy_extras.io_utils import poll_file_object_drop + from bpy.props import ( StringProperty, BoolProperty, @@ -24,6 +29,12 @@ from .logging import DMX_Log +def createDMXcollection(): + dmx = bpy.context.scene.dmx + if not dmx.collection: + bpy.context.scene.dmx.new() + + class DMX_OT_Import_GDTF(bpy.types.Operator, ImportHelper): """Import GDTF""" @@ -71,6 +82,9 @@ class DMX_OT_Import_GDTF(bpy.types.Operator, ImportHelper): units: IntProperty(name=_("Units"), description=_("How many units of this light to add"), default=1, min=1, max=1024) def draw(self, context): + dmx = context.scene.dmx + if not dmx.collection: + Timer(0, createDMXcollection, ()).start() layout = self.layout layout.use_property_split = True layout.use_property_decorate = False @@ -91,8 +105,6 @@ def execute(self, context): folder_path = os.path.dirname(os.path.realpath(__file__)) folder_path = os.path.join(folder_path, "assets", "profiles") dmx = context.scene.dmx - if not dmx.collection: - context.scene.dmx.new() address = self.address universe = self.universe @@ -136,11 +148,18 @@ def execute(self, context): return {"FINISHED"} -class DMX_IO_FH_GDTF(bpy.types.FileHandler): - bl_idname = "IO_FH_gdtf" - bl_label = "GDTF" - bl_import_operator = "dmx.import_gdtf_into_scene" - bl_file_extensions = ".gdtf" +if bpy.app.version >= (4, 1): + + class DMX_IO_FH_GDTF(bpy.types.FileHandler): + bl_idname = "IO_FH_gdtf" + bl_label = "GDTF" + bl_import_operator = "dmx.import_gdtf_into_scene" + bl_file_extensions = ".gdtf" + + @classmethod + def poll_drop(cls, context): + if bpy.app.version >= (4, 2): + return poll_file_object_drop(context) def menu_func_import(self, context): @@ -149,11 +168,13 @@ def menu_func_import(self, context): def register(): bpy.utils.register_class(DMX_OT_Import_GDTF) - bpy.utils.register_class(DMX_IO_FH_GDTF) bpy.types.TOPBAR_MT_file_import.append(menu_func_import) + if bpy.app.version >= (4, 1): + bpy.utils.register_class(DMX_IO_FH_GDTF) def unregister(): bpy.types.TOPBAR_MT_file_import.remove(menu_func_import) - bpy.utils.unregister_class(DMX_IO_FH_GDTF) + if bpy.app.version >= (4, 1): + bpy.utils.unregister_class(DMX_IO_FH_GDTF) bpy.utils.unregister_class(DMX_OT_Import_GDTF) diff --git a/in_out_mvr.py b/in_out_mvr.py index bdf8f87d..79324e9c 100644 --- a/in_out_mvr.py +++ b/in_out_mvr.py @@ -1,15 +1,28 @@ import bpy import os -from bpy_extras.io_utils import ( - ImportHelper, - ExportHelper, -) + +from bpy_extras.io_utils import ImportHelper, ExportHelper + +if bpy.app.version >= (4, 2): + from bpy_extras.io_utils import poll_file_object_drop + from bpy.props import ( StringProperty, CollectionProperty, ) -class DMX_OT_Import_MVR(bpy.types.Operator, ImportHelper): +from bpy.types import Operator + +from threading import Timer + + +def createDMXcollection(): + dmx = bpy.context.scene.dmx + if not dmx.collection: + bpy.context.scene.dmx.new() + + +class DMX_OT_Import_MVR(Operator, ImportHelper): """Import My Virtual Rig""" bl_idname = "dmx.import_mvr_into_scene" @@ -22,14 +35,15 @@ class DMX_OT_Import_MVR(bpy.types.Operator, ImportHelper): directory: StringProperty(subtype="DIR_PATH") def draw(self, context): + dmx = context.scene.dmx + if not dmx.collection: + Timer(0, createDMXcollection, ()).start() layout = self.layout layout.use_property_split = True layout.use_property_decorate = False def execute(self, context): dmx = context.scene.dmx - if not dmx.collection: - context.scene.dmx.new() for file in self.files: if not file.name: continue @@ -39,7 +53,7 @@ def execute(self, context): return {"FINISHED"} -class DMX_OT_Export_MVR(bpy.types.Operator, ExportHelper): +class DMX_OT_Export_MVR(Operator, ExportHelper): """Export My Virtual Rig""" bl_idname = "dmx.export_mvr_from_scene" @@ -49,15 +63,16 @@ class DMX_OT_Export_MVR(bpy.types.Operator, ExportHelper): filename_ext = ".mvr" def draw(self, context): + dmx = context.scene.dmx + if not dmx.collection: + Timer(0, createDMXcollection, ()).start() layout = self.layout layout.use_property_split = True layout.use_property_decorate = False def execute(self, context): dmx = context.scene.dmx - if not dmx.collection: - context.scene.dmx.new() - dmx = context.scene.dmx + print(self.filepath) result = dmx.export_mvr(self.filepath) if result.ok: @@ -68,12 +83,19 @@ def execute(self, context): return {"FINISHED"} -class DMX_IO_FH_MVR(bpy.types.FileHandler): - bl_idname = "IO_FH_mvr" - bl_label = "MVR" - bl_import_operator = "dmx.import_mvr_into_scene" - bl_export_operator = "dmx.export_mvr_from_scene" - bl_file_extensions = ".mvr" +if bpy.app.version >= (4, 1): + + class DMX_IO_FH_MVR(bpy.types.FileHandler): + bl_idname = "IO_FH_mvr" + bl_label = "MVR" + bl_import_operator = "dmx.import_mvr_into_scene" + bl_export_operator = "dmx.export_mvr_from_scene" + bl_file_extensions = ".mvr" + + @classmethod + def poll_drop(cls, context): + if bpy.app.version >= (4, 2): + return poll_file_object_drop(context) def menu_func_export(self, context): @@ -87,14 +109,16 @@ def menu_func_import(self, context): def register(): bpy.utils.register_class(DMX_OT_Import_MVR) bpy.utils.register_class(DMX_OT_Export_MVR) - bpy.utils.register_class(DMX_IO_FH_MVR) bpy.types.TOPBAR_MT_file_import.append(menu_func_import) bpy.types.TOPBAR_MT_file_export.append(menu_func_export) + if bpy.app.version >= (4, 1): + bpy.utils.register_class(DMX_IO_FH_MVR) def unregister(): bpy.types.TOPBAR_MT_file_import.remove(menu_func_import) bpy.types.TOPBAR_MT_file_export.remove(menu_func_export) - bpy.utils.unregister_class(DMX_IO_FH_MVR) + if bpy.app.version >= (4, 1): + bpy.utils.unregister_class(DMX_IO_FH_MVR) bpy.utils.unregister_class(DMX_OT_Import_MVR) bpy.utils.unregister_class(DMX_OT_Export_MVR)