1 # SPDX-License-Identifier: GPL-2.0-or-later
5 #---------------------------------------------#
7 #---------------------------------------------#
9 - add file selection for single and multiple files
10 - option to enable/disable fake users
13 #---------------------------------------------#
16 from bpy
.props
import *
20 "name": "Import BrushSet",
21 "author": "Daniel Grauer (kromar), CansecoGPC",
23 "blender": (2, 80, 0),
24 "location": "File > Import > BrushSet",
25 "description": "Imports all image files from a folder.",
26 "warning": '', # used for warning icon and text in addons panel
27 "doc_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Import-Export/BrushSet",
28 "tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
29 "category": "Import-Export",
32 #---------------------------------------------#
34 # extension filter (alternative use mimetypes)
35 # TODO: rewrite so it tries to load image and if it fails we know its not a format blender can load
49 #---------------------------------------------#
53 def LoadBrushSet(filepath
, filename
):
54 for file in os
.listdir(filepath
):
55 path
= (filepath
+ file)
58 (f1
, f2
) = os
.path
.split(filepath
)
59 (f3
, foldername
) = os
.path
.split(f1
)
61 # filter files by extensions (filter images)
62 if any(file.lower().endswith(ext
) for ext
in ext_list
):
65 texture
= bpy
.data
.textures
.new(file, 'IMAGE')
66 texture
.use_fake_user
= fakeUser
67 print("texture: ", texture
)
69 # now we need to load the image into data
70 image
= bpy
.data
.images
.load(path
)
71 image
.use_fake_user
= fakeUser
72 # image.source = 'FILE' #default is FILE so can remove this
73 # image.filepath = path
74 print("image: ", image
, " ", path
)
75 print("texturename: ", texture
.name
)
77 # and assign the image to the texture
78 bpy
.data
.textures
[texture
.name
].image
= image
81 print("Brush Set imported!")
83 #---------------------------------------------#
85 class BrushSetImporter(bpy
.types
.Operator
):
87 bl_idname
= "import_image.brushset"
88 bl_label
= "Import BrushSet"
90 filename
: StringProperty(name
= "File Name",
91 description
= "filepath",
94 options
= {'ANIMATABLE'},
97 filepath
: StringProperty(name
= "File Name",
98 description
= "filepath",
101 options
= {'ANIMATABLE'},
104 def execute(self
, context
):
105 LoadBrushSet(self
.properties
.filepath
, self
.properties
.filename
)
108 def invoke(self
, context
, event
):
109 wm
= context
.window_manager
110 wm
.fileselect_add(self
)
111 return {'RUNNING_MODAL'}
113 #---------------------------------------------#
115 def menu_func(self
, context
):
116 # clear the default name for import
119 self
.layout
.operator(BrushSetImporter
.bl_idname
, text
= "Brush Set").filename
= import_name
122 #---------------------------------------------#
124 #---------------------------------------------#
127 class Brush_set_UI(bpy.types.Panel):
129 bl_space_type ='USER_PREFERENCES'
130 bl_label = 'Brush_Path'
131 bl_region_type = 'WINDOW'
132 bl_options = {'HIDE_HEADER'}
134 def draw(self, context):
138 column = layout.column(align=True)
139 column.label(text='Brush Directory:')
140 column.prop(scn,'filepath')
143 #---------------------------------------------#
151 from bpy
.utils
import register_class
154 bpy
.types
.TOPBAR_MT_file_import
.append(menu_func
)
158 from bpy
.utils
import unregister_class
159 for cls
in reversed(classes
):
160 unregister_class(cls
)
161 bpy
.types
.TOPBAR_MT_file_import
.remove(menu_func
)
164 if __name__
== "__main__":