1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
21 #---------------------------------------------#
23 #---------------------------------------------#
25 - add file selection for single and multiple files
26 - option to enable/disable fake users
29 #---------------------------------------------#
32 from bpy
.props
import *
36 "name": "Import BrushSet",
37 "author": "Daniel Grauer (kromar), CansecoGPC",
39 "blender": (2, 80, 0),
40 "location": "File > Import > BrushSet",
41 "description": "Imports all image files from a folder.",
42 "warning": '', # used for warning icon and text in addons panel
43 "doc_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Import-Export/BrushSet",
44 "tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
45 "category": "Import-Export",
48 #---------------------------------------------#
50 # extension filter (alternative use mimetypes)
51 # TODO: rewrite so it tries to load image and if it fails we know its not a format blender can load
65 #---------------------------------------------#
69 def LoadBrushSet(filepath
, filename
):
70 for file in os
.listdir(filepath
):
71 path
= (filepath
+ file)
74 (f1
, f2
) = os
.path
.split(filepath
)
75 (f3
, foldername
) = os
.path
.split(f1
)
77 # filter files by extensions (filter images)
78 if any(file.lower().endswith(ext
) for ext
in ext_list
):
81 texture
= bpy
.data
.textures
.new(file, 'IMAGE')
82 texture
.use_fake_user
= fakeUser
83 print("texture: ", texture
)
85 # now we need to load the image into data
86 image
= bpy
.data
.images
.load(path
)
87 image
.use_fake_user
= fakeUser
88 # image.source = 'FILE' #default is FILE so can remove this
89 # image.filepath = path
90 print("image: ", image
, " ", path
)
91 print("texturename: ", texture
.name
)
93 # and assign the image to the texture
94 bpy
.data
.textures
[texture
.name
].image
= image
97 print("Brush Set imported!")
99 #---------------------------------------------#
101 class BrushSetImporter(bpy
.types
.Operator
):
103 bl_idname
= "import_image.brushset"
104 bl_label
= "Import BrushSet"
106 filename
: StringProperty(name
= "File Name",
107 description
= "filepath",
110 options
= {'ANIMATABLE'},
113 filepath
: StringProperty(name
= "File Name",
114 description
= "filepath",
117 options
= {'ANIMATABLE'},
120 def execute(self
, context
):
121 LoadBrushSet(self
.properties
.filepath
, self
.properties
.filename
)
124 def invoke(self
, context
, event
):
125 wm
= context
.window_manager
126 wm
.fileselect_add(self
)
127 return {'RUNNING_MODAL'}
129 #---------------------------------------------#
131 def menu_func(self
, context
):
132 # clear the default name for import
135 self
.layout
.operator(BrushSetImporter
.bl_idname
, text
= "Brush Set").filename
= import_name
138 #---------------------------------------------#
140 #---------------------------------------------#
143 class Brush_set_UI(bpy.types.Panel):
145 bl_space_type ='USER_PREFERENCES'
146 bl_label = 'Brush_Path'
147 bl_region_type = 'WINDOW'
148 bl_options = {'HIDE_HEADER'}
150 def draw(self, context):
154 column = layout.column(align=True)
155 column.label(text='Brush Directory:')
156 column.prop(scn,'filepath')
159 #---------------------------------------------#
167 from bpy
.utils
import register_class
170 bpy
.types
.TOPBAR_MT_file_import
.append(menu_func
)
174 from bpy
.utils
import unregister_class
175 for cls
in reversed(classes
):
176 unregister_class(cls
)
177 bpy
.types
.TOPBAR_MT_file_import
.remove(menu_func
)
180 if __name__
== "__main__":