Fix: ensure loaded path is folder and not file #104812

Closed
Daniel Grauer wants to merge 4 commits from DanielGrauer:fix-error-when-file-is-selected into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

View File

@ -13,7 +13,6 @@
#---------------------------------------------# #---------------------------------------------#
import bpy import bpy
import os import os
from bpy.props import *
# addon description # addon description
bl_info = { bl_info = {
@ -50,12 +49,13 @@ ext_list = ['.bmp',
fakeUser = False fakeUser = False
def LoadBrushSet(filepath, filename): def LoadBrushSet(directory):
for file in os.listdir(filepath):
path = (filepath + file) for file in os.listdir(directory):
path = os.path.join(directory + file)
# get folder name # get folder name
(f1, f2) = os.path.split(filepath) (f1, f2) = os.path.split(directory)
(f3, foldername) = os.path.split(f1) (f3, foldername) = os.path.split(f1)
# filter files by extensions (filter images) # filter files by extensions (filter images)
@ -87,22 +87,18 @@ class BrushSetImporter(bpy.types.Operator):
bl_idname = "import_image.brushset" bl_idname = "import_image.brushset"
bl_label = "Import BrushSet" bl_label = "Import BrushSet"
filename: StringProperty(name = "File Name", directory: bpy.props.StringProperty(name="Directory", options={"HIDDEN"})
description = "filepath",
default = "",
maxlen = 1024,
options = {'ANIMATABLE'},
subtype = 'NONE')
filepath: StringProperty(name = "File Name", set_default_filters: bool = True
description = "filepath", def draw(self, context):
default = "", if self.set_default_filters:
maxlen = 1024, context.space_data.params.use_filter = True
options = {'ANIMATABLE'}, context.space_data.params.use_filter_folder = True
subtype = 'NONE') context.space_data.params.use_filter_image = True
self.set_default_filters = False
def execute(self, context): def execute(self, context):
LoadBrushSet(self.properties.filepath, self.properties.filename) LoadBrushSet(self.directory)
return {'FINISHED'} return {'FINISHED'}
def invoke(self, context, event): def invoke(self, context, event):
@ -148,16 +144,14 @@ classes = (
def register(): def register():
from bpy.utils import register_class
for cls in classes: for cls in classes:
register_class(cls) bpy.utils.register_class(cls)
bpy.types.TOPBAR_MT_file_import.append(menu_func) bpy.types.TOPBAR_MT_file_import.append(menu_func)
def unregister(): def unregister():
from bpy.utils import unregister_class
for cls in reversed(classes): for cls in reversed(classes):
unregister_class(cls) bpy.utils.unregister_class(cls)
bpy.types.TOPBAR_MT_file_import.remove(menu_func) bpy.types.TOPBAR_MT_file_import.remove(menu_func)