Export_3ds: Improved distance cue node search
[blender-addons.git] / io_import_BrushSet.py
blob4b4c6fae8f3e16a3fd11291e60c47d5f8c26c390
1 # SPDX-FileCopyrightText: 2020-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 import bpy
6 import os
7 from bpy.props import (
8 StringProperty,
11 bl_info = {
12 "name": "Import BrushSet",
13 "author": "Daniel Grauer (kromar), CansecoGPC",
14 "version": (1, 3, 1),
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",
24 fakeUser = False
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):
31 continue
33 # Load the image into data.
34 path = os.path.join(dirpath, file)
35 try:
36 image = bpy.data.images.load(path)
37 except BaseException as ex:
38 print("Failed to load %r, error: %r" % (file, ex))
39 continue
41 image.use_fake_user = fakeUser
43 # Create new texture.
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.
50 texture.image = image
52 print("imported:", repr(file))
54 print("Brush Set imported!")
56 # -----------------------------------------------------------------------------
59 class BrushSetImporter(bpy.types.Operator):
60 '''Load Brush Set'''
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):
68 if self.temp_filters:
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(
75 name="Directory",
76 description="Directory",
77 maxlen=1024,
78 subtype='DIR_PATH',
81 def execute(self, context):
82 load_brush_set(self.directory)
83 return {'FINISHED'}
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 # -----------------------------------------------------------------------------
98 # GUI
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):
110 scn = context.scene
111 layout = self.layout
112 column = layout.column(align=True)
113 column.label(text='Brush Directory:')
114 column.prop(scn,'filepath')
117 # -----------------------------------------------------------------------------
119 classes = (
120 BrushSetImporter,
124 def register():
125 from bpy.utils import register_class
126 for cls in classes:
127 register_class(cls)
128 bpy.types.TOPBAR_MT_file_import.append(menu_func)
131 def unregister():
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__":
139 register()