Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support multiple files for drag-drop import
Browse files Browse the repository at this point in the history
matyalatte committed May 18, 2024
1 parent c0af68c commit 98c423e
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions addons/blender_dds_addon/ui/drag_drop.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import time
import traceback

@@ -18,27 +19,31 @@ class DDS_OT_drag_drop_import(bpy.types.Operator):
"""Operator to import dropped .dds files."""
bl_idname = "dds.drag_drop_import"
bl_label = "Import a dropped dds file"
filepath: bpy.props.StringProperty(subtype='FILE_PATH', options={'SKIP_SAVE'})
directory: bpy.props.StringProperty(subtype='FILE_PATH', options={'SKIP_SAVE'})
files: bpy.props.CollectionProperty(type=bpy.types.OperatorFileListElement, options={'SKIP_SAVE'})

@classmethod
def poll(cls, context):
return is_dds_panel(context)

def execute(self, context):
""" Calls to this Operator can set unfiltered filepaths, ensure the file extension is .txt. """
if not self.filepath or not self.filepath.endswith(".dds"):
if not self.directory or not self.files:
return {'CANCELLED'}

texconv = Texconv()
astcenc = Astcenc()

try:
start_time = time.time()

import_dds(context, self.filepath,
texconv=texconv, astcenc=astcenc)
flush_stdout()
count = 1
count = 0

for file in self.files:
filepath = os.path.join(self.directory, file.name)
import_dds(context, filepath,
texconv=texconv, astcenc=astcenc)
flush_stdout()
count += 1
elapsed_s = f'{(time.time() - start_time):.2f}s'
if count == 0:
raise RuntimeError("Imported no DDS files.")
@@ -62,7 +67,7 @@ def execute(self, context):
return ret

def invoke(self, context, event):
if self.filepath:
if self.directory and self.files:
return self.execute(context)
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}

0 comments on commit 98c423e

Please sign in to comment.