Skip to content

Commit

Permalink
Ensure app compatiblity for In/Out operations
Browse files Browse the repository at this point in the history
  • Loading branch information
vanous committed Jul 23, 2024
1 parent faf63b7 commit 6b0cb08
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 31 deletions.
45 changes: 33 additions & 12 deletions in_gdtf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"""

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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)
60 changes: 41 additions & 19 deletions in_out_mvr.py
Original file line number Diff line number Diff line change
@@ -1,16 +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,
)

from bpy.types import Operator

from threading import Timer

class DMX_OT_Import_MVR(bpy.types.Operator, ImportHelper):

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"
Expand All @@ -23,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
Expand All @@ -40,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"
Expand All @@ -50,15 +63,15 @@ 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)

Expand All @@ -70,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):
Expand All @@ -89,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)

0 comments on commit 6b0cb08

Please sign in to comment.