GPencil Tools: Canvas rotate improvement
[blender-addons.git] / io_import_BrushSet.py
blob0c788fcba7285ef229e88e73f44229985ad8a934
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 #####
19 # <pep8-80 compliant>
21 #---------------------------------------------#
22 # todo
23 #---------------------------------------------#
24 '''
25 - add file selection for single and multiple files
26 - option to enable/disable fake users
27 '''
29 #---------------------------------------------#
30 import bpy
31 import os
32 from bpy.props import *
34 # addon description
35 bl_info = {
36 "name": "Import BrushSet",
37 "author": "Daniel Grauer (kromar), CansecoGPC",
38 "version": (1, 2, 2),
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
52 ext_list = ['.bmp',
53 '.png',
54 '.jpg',
55 '.jp2',
56 '.rgb',
57 '.dds',
58 '.hdr',
59 '.exr',
60 '.dpx',
61 '.cin',
62 '.tga',
63 '.tif'];
65 #---------------------------------------------#
67 fakeUser = False
69 def LoadBrushSet(filepath, filename):
70 for file in os.listdir(filepath):
71 path = (filepath + file)
73 # get folder name
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):
79 print("file: ", file)
80 # create new texture
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):
102 '''Load Brush Set'''
103 bl_idname = "import_image.brushset"
104 bl_label = "Import BrushSet"
106 filename: StringProperty(name = "File Name",
107 description = "filepath",
108 default = "",
109 maxlen = 1024,
110 options = {'ANIMATABLE'},
111 subtype = 'NONE')
113 filepath: StringProperty(name = "File Name",
114 description = "filepath",
115 default = "",
116 maxlen = 1024,
117 options = {'ANIMATABLE'},
118 subtype = 'NONE')
120 def execute(self, context):
121 LoadBrushSet(self.properties.filepath, self.properties.filename)
122 return {'FINISHED'}
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
133 import_name = ""
135 self.layout.operator(BrushSetImporter.bl_idname, text = "Brush Set").filename = import_name
138 #---------------------------------------------#
139 # GUI
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):
152 scn = context.scene
153 layout = self.layout
154 column = layout.column(align=True)
155 column.label(text='Brush Directory:')
156 column.prop(scn,'filepath')
159 #---------------------------------------------#
161 classes = (
162 BrushSetImporter,
166 def register():
167 from bpy.utils import register_class
168 for cls in classes:
169 register_class(cls)
170 bpy.types.TOPBAR_MT_file_import.append(menu_func)
173 def unregister():
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__":
181 register()