Fix T98039: Node Wrangler node preview no longer working
[blender-addons.git] / io_import_BrushSet.py
blobe64cacebd5a7dc97e4864e01ad9b34795a482e09
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 # <pep8-80 compliant>
5 #---------------------------------------------#
6 # todo
7 #---------------------------------------------#
8 '''
9 - add file selection for single and multiple files
10 - option to enable/disable fake users
11 '''
13 #---------------------------------------------#
14 import bpy
15 import os
16 from bpy.props import *
18 # addon description
19 bl_info = {
20 "name": "Import BrushSet",
21 "author": "Daniel Grauer (kromar), CansecoGPC",
22 "version": (1, 2, 2),
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
36 ext_list = ['.bmp',
37 '.png',
38 '.jpg',
39 '.jp2',
40 '.rgb',
41 '.dds',
42 '.hdr',
43 '.exr',
44 '.dpx',
45 '.cin',
46 '.tga',
47 '.tif'];
49 #---------------------------------------------#
51 fakeUser = False
53 def LoadBrushSet(filepath, filename):
54 for file in os.listdir(filepath):
55 path = (filepath + file)
57 # get folder name
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):
63 print("file: ", file)
64 # create new texture
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):
86 '''Load Brush Set'''
87 bl_idname = "import_image.brushset"
88 bl_label = "Import BrushSet"
90 filename: StringProperty(name = "File Name",
91 description = "filepath",
92 default = "",
93 maxlen = 1024,
94 options = {'ANIMATABLE'},
95 subtype = 'NONE')
97 filepath: StringProperty(name = "File Name",
98 description = "filepath",
99 default = "",
100 maxlen = 1024,
101 options = {'ANIMATABLE'},
102 subtype = 'NONE')
104 def execute(self, context):
105 LoadBrushSet(self.properties.filepath, self.properties.filename)
106 return {'FINISHED'}
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
117 import_name = ""
119 self.layout.operator(BrushSetImporter.bl_idname, text = "Brush Set").filename = import_name
122 #---------------------------------------------#
123 # GUI
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):
136 scn = context.scene
137 layout = self.layout
138 column = layout.column(align=True)
139 column.label(text='Brush Directory:')
140 column.prop(scn,'filepath')
143 #---------------------------------------------#
145 classes = (
146 BrushSetImporter,
150 def register():
151 from bpy.utils import register_class
152 for cls in classes:
153 register_class(cls)
154 bpy.types.TOPBAR_MT_file_import.append(menu_func)
157 def unregister():
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__":
165 register()