mirrored from https://projects.blender.org/blender/blender-addons.git
-
Notifications
You must be signed in to change notification settings - Fork 189
/
io_import_BrushSet.py
139 lines (103 loc) · 3.68 KB
/
io_import_BrushSet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# SPDX-FileCopyrightText: 2020-2022 Blender Foundation
#
# SPDX-License-Identifier: GPL-2.0-or-later
import bpy
import os
from bpy.props import (
StringProperty,
)
bl_info = {
"name": "Import BrushSet",
"author": "Daniel Grauer (kromar), CansecoGPC",
"version": (1, 3, 1),
"blender": (2, 80, 0),
"location": "File > Import > BrushSet",
"description": "Imports all image files from a folder.",
"warning": '', # used for warning icon and text in addons panel
"doc_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Import-Export/BrushSet",
"tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
"category": "Import-Export",
}
fakeUser = False
def load_brush_set(dirpath):
extensions = tuple(bpy.path.extensions_image)
for file in os.listdir(dirpath):
if not file.lower().endswith(extensions):
continue
# Load the image into data.
path = os.path.join(dirpath, file)
try:
image = bpy.data.images.load(path)
except BaseException as ex:
print("Failed to load %r, error: %r" % (file, ex))
continue
image.use_fake_user = fakeUser
# Create new texture.
# NOTE: use the image name instead of `file` in case
# it's encoding isn't `utf-8` compatible.
texture = bpy.data.textures.new(image.name, 'IMAGE')
texture.use_fake_user = fakeUser
# Assign the image to the texture.
texture.image = image
print("imported:", repr(file))
print("Brush Set imported!")
# -----------------------------------------------------------------------------
class BrushSetImporter(bpy.types.Operator):
'''Load Brush Set'''
bl_idname = "import_image.brushset"
bl_label = "Import BrushSet"
# creating a temporary filter to avoid overriding the users filters
temp_filters: bool = True
def draw(self, context):
if self.temp_filters:
context.space_data.params.use_filter = True
context.space_data.params.use_filter_folder = True
context.space_data.params.use_filter_image = True
self.temp_filters = False
directory: StringProperty(
name="Directory",
description="Directory",
maxlen=1024,
subtype='DIR_PATH',
)
def execute(self, context):
load_brush_set(self.directory)
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
wm.fileselect_add(self)
return {'RUNNING_MODAL'}
# -----------------------------------------------------------------------------
def menu_func(self, context):
self.layout.operator(BrushSetImporter.bl_idname, text="Brush Set")
# -----------------------------------------------------------------------------
# GUI
'''
class Brush_set_UI(bpy.types.Panel):
bl_space_type ='USER_PREFERENCES'
bl_label = 'Brush_Path'
bl_region_type = 'WINDOW'
bl_options = {'HIDE_HEADER'}
def draw(self, context):
scn = context.scene
layout = self.layout
column = layout.column(align=True)
column.label(text='Brush Directory:')
column.prop(scn,'filepath')
'''
# -----------------------------------------------------------------------------
classes = (
BrushSetImporter,
)
def register():
from bpy.utils import register_class
for cls in classes:
register_class(cls)
bpy.types.TOPBAR_MT_file_import.append(menu_func)
def unregister():
from bpy.utils import unregister_class
for cls in reversed(classes):
unregister_class(cls)
bpy.types.TOPBAR_MT_file_import.remove(menu_func)
if __name__ == "__main__":
register()