1 # SPDX-License-Identifier: GPL-2.0-or-later
3 #---------------------------------------------#
5 #---------------------------------------------#
7 - add file selection for single and multiple files
8 - option to enable/disable fake users
11 #---------------------------------------------#
14 from bpy
.props
import *
18 "name": "Import BrushSet",
19 "author": "Daniel Grauer (kromar), CansecoGPC",
21 "blender": (2, 80, 0),
22 "location": "File > Import > BrushSet",
23 "description": "Imports all image files from a folder.",
24 "warning": '', # used for warning icon and text in addons panel
25 "doc_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Import-Export/BrushSet",
26 "tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
27 "category": "Import-Export",
30 #---------------------------------------------#
32 # extension filter (alternative use mimetypes)
33 # TODO: rewrite so it tries to load image and if it fails we know its not a format blender can load
47 #---------------------------------------------#
51 def LoadBrushSet(filepath
, filename
):
52 for file in os
.listdir(filepath
):
53 path
= (filepath
+ file)
56 (f1
, f2
) = os
.path
.split(filepath
)
57 (f3
, foldername
) = os
.path
.split(f1
)
59 # filter files by extensions (filter images)
60 if any(file.lower().endswith(ext
) for ext
in ext_list
):
63 texture
= bpy
.data
.textures
.new(file, 'IMAGE')
64 texture
.use_fake_user
= fakeUser
65 print("texture: ", texture
)
67 # now we need to load the image into data
68 image
= bpy
.data
.images
.load(path
)
69 image
.use_fake_user
= fakeUser
70 # image.source = 'FILE' #default is FILE so can remove this
71 # image.filepath = path
72 print("image: ", image
, " ", path
)
73 print("texturename: ", texture
.name
)
75 # and assign the image to the texture
76 bpy
.data
.textures
[texture
.name
].image
= image
79 print("Brush Set imported!")
81 #---------------------------------------------#
83 class BrushSetImporter(bpy
.types
.Operator
):
85 bl_idname
= "import_image.brushset"
86 bl_label
= "Import BrushSet"
88 filename
: StringProperty(name
= "File Name",
89 description
= "filepath",
92 options
= {'ANIMATABLE'},
95 filepath
: StringProperty(name
= "File Name",
96 description
= "filepath",
99 options
= {'ANIMATABLE'},
102 def execute(self
, context
):
103 LoadBrushSet(self
.properties
.filepath
, self
.properties
.filename
)
106 def invoke(self
, context
, event
):
107 wm
= context
.window_manager
108 wm
.fileselect_add(self
)
109 return {'RUNNING_MODAL'}
111 #---------------------------------------------#
113 def menu_func(self
, context
):
114 # clear the default name for import
117 self
.layout
.operator(BrushSetImporter
.bl_idname
, text
= "Brush Set").filename
= import_name
120 #---------------------------------------------#
122 #---------------------------------------------#
125 class Brush_set_UI(bpy.types.Panel):
127 bl_space_type ='USER_PREFERENCES'
128 bl_label = 'Brush_Path'
129 bl_region_type = 'WINDOW'
130 bl_options = {'HIDE_HEADER'}
132 def draw(self, context):
136 column = layout.column(align=True)
137 column.label(text='Brush Directory:')
138 column.prop(scn,'filepath')
141 #---------------------------------------------#
149 from bpy
.utils
import register_class
152 bpy
.types
.TOPBAR_MT_file_import
.append(menu_func
)
156 from bpy
.utils
import unregister_class
157 for cls
in reversed(classes
):
158 unregister_class(cls
)
159 bpy
.types
.TOPBAR_MT_file_import
.remove(menu_func
)
162 if __name__
== "__main__":