1 # SPDX-FileCopyrightText: 2020-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
7 from bpy
.props
import (
12 "name": "Import BrushSet",
13 "author": "Daniel Grauer (kromar), CansecoGPC",
15 "blender": (2, 80, 0),
16 "location": "File > Import > BrushSet",
17 "description": "Imports all image files from a folder.",
18 "warning": '', # used for warning icon and text in addons panel
19 "doc_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Import-Export/BrushSet",
20 "tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
21 "category": "Import-Export",
27 def load_brush_set(dirpath
):
28 extensions
= tuple(bpy
.path
.extensions_image
)
29 for file in os
.listdir(dirpath
):
30 if not file.lower().endswith(extensions
):
33 # Load the image into data.
34 path
= os
.path
.join(dirpath
, file)
36 image
= bpy
.data
.images
.load(path
)
37 except BaseException
as ex
:
38 print("Failed to load %r, error: %r" % (file, ex
))
41 image
.use_fake_user
= fakeUser
44 # NOTE: use the image name instead of `file` in case
45 # it's encoding isn't `utf-8` compatible.
46 texture
= bpy
.data
.textures
.new(image
.name
, 'IMAGE')
47 texture
.use_fake_user
= fakeUser
49 # Assign the image to the texture.
52 print("imported:", repr(file))
54 print("Brush Set imported!")
56 # -----------------------------------------------------------------------------
59 class BrushSetImporter(bpy
.types
.Operator
):
61 bl_idname
= "import_image.brushset"
62 bl_label
= "Import BrushSet"
65 # creating a temporary filter to avoid overriding the users filters
66 temp_filters
: bool = True
67 def draw(self
, context
):
69 context
.space_data
.params
.use_filter
= True
70 context
.space_data
.params
.use_filter_folder
= True
71 context
.space_data
.params
.use_filter_image
= True
72 self
.temp_filters
= False
74 directory
: StringProperty(
76 description
="Directory",
81 def execute(self
, context
):
82 load_brush_set(self
.directory
)
85 def invoke(self
, context
, event
):
86 wm
= context
.window_manager
87 wm
.fileselect_add(self
)
88 return {'RUNNING_MODAL'}
90 # -----------------------------------------------------------------------------
93 def menu_func(self
, context
):
94 self
.layout
.operator(BrushSetImporter
.bl_idname
, text
="Brush Set")
97 # -----------------------------------------------------------------------------
101 class Brush_set_UI(bpy.types.Panel):
103 bl_space_type ='USER_PREFERENCES'
104 bl_label = 'Brush_Path'
105 bl_region_type = 'WINDOW'
106 bl_options = {'HIDE_HEADER'}
108 def draw(self, context):
112 column = layout.column(align=True)
113 column.label(text='Brush Directory:')
114 column.prop(scn,'filepath')
117 # -----------------------------------------------------------------------------
125 from bpy
.utils
import register_class
128 bpy
.types
.TOPBAR_MT_file_import
.append(menu_func
)
132 from bpy
.utils
import unregister_class
133 for cls
in reversed(classes
):
134 unregister_class(cls
)
135 bpy
.types
.TOPBAR_MT_file_import
.remove(menu_func
)
138 if __name__
== "__main__":