-
Notifications
You must be signed in to change notification settings - Fork 1
/
__init__.py
254 lines (197 loc) · 9.25 KB
/
__init__.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
Custom Weight Paint Presets
Save your Custom Weight Paint colors as presets, for easy re-use.
"""
bl_info = {
"name": "Save Custom Weight Paint Presets",
"author": "Rombout Versluijs",
"version": (0,0,9),
"blender": (2, 83, 0),
"location": "Preferences > Editting > Weight Paint",
"description": "Save custom color ramps for weight painting",
"tracker_url": "https://github.com/schroef/Save-Custom-Weight-Paint-Presets/issues",
"doc_url": "https://github.com/schroef/Save-Custom-Weight-Paint-Presets",
"category": "Preferences",
}
import bpy, os
from shutil import Error
from . presets import AddPresetBase
class SCWPP_PREFS_MT_weight_paint_presets(bpy.types.Menu):
"""List of Weight Paint presets"""
bl_label = "Weight Paint Presets"
# script_file = os.path.realpath(__file__)
# directory = os.path.dirname(script_file)
# target_path = os.path.join(directory,"presets\\")
# target_path = directory
# searchpaths= str(target_path)
# preset_subdir = str('C:/Users/romboutversluijs/AppData/Roaming/Blender Foundation/Blender/2.91/scripts/addons/Save-Custom-Weight-Paint-Presets/presets/')
# preset_subdir = "presets"
# Addon preset path
# prop_filepath= target_path
preset_subdir = "custom_weight_paint_colors"
preset_operator = "script.execute_preset"
draw = bpy.types.Menu.draw_preset
class SCWPP_AddPresetWeightPaint(AddPresetBase, bpy.types.Operator):
"""Add or remove a Weight Paint preset"""
bl_idname = "preferences.weight_paint_preset_add"
bl_label = "Add Weight Paint Preset"
preset_menu = "SCWPP_PREFS_MT_weight_paint_presets"
preset_defines = [
"prefs = bpy.context.preferences",
]
preset_values = [
"prefs.view.use_weight_color_range",
"prefs.view.weight_color_range.color_mode",
"prefs.view.weight_color_range.interpolation",
]
preset_subdir = "custom_weight_paint_colors"
# preset_subdir = "custom_weight_paint_colors"
# def drawcentered(self, context, layout):
# layout = self.layout
# width = context.region.width
# ui_scale = context.preferences.system.ui_scale
# # No horizontal margin if region is rather small.
# is_wide = width > (350 * ui_scale)
# layout.use_property_split = True
# layout.use_property_decorate = False # No animation.
# row = layout.row()
# if is_wide:
# row.label() # Needed so col below is centered.
# col = row.column()
# col.ui_units_x = 50
# # Implemented by sub-classes.
# self.draw_centered(context, col)
# if is_wide:
# row.label() # Needed so col above is centered.
def install_presets():
# https://www.geeksforgeeks.org/how-to-move-files-and-directories-in-python/
import shutil
# Source path
cwppFold = "custom_weight_paint_colors"
script_file = os.path.realpath(__file__)
directory = os.path.dirname(script_file)
presetSrc = os.path.join("presets", cwppFold)
source = os.path.join(directory, presetSrc)
# Possible fix for bl3.0
# fix for user_resource error > from store_vieews
# https://git.blender.org/gitweb/gitweb.cgi/blender-addons.git/blob/HEAD:/space_view3d_stored_views/stored_views_test.py
# paths = bpy.utils.preset_paths("stored_views")
# if not paths:
# stored_views preset folder doesn't exist, so create it
# paths = [os.path.join(bpy.utils.user_resource('SCRIPTS'), "presets","stored_views")]
# other fix from eevee_presets
# from pathlib import Path
# user_path = Path(bpy.utils.resource_path('USER'))
# preset_path = user_path / Path(f"scripts/presets/{PRESET_SUBDIR}")
# bl3 fix > https://blender.stackexchange.com/a/245232/7631
# Destination path
if bpy.app.version[0] >= 3:
destination = bpy.utils.user_resource('SCRIPTS',path="presets/",create=True)
else:
destination = bpy.utils.user_resource('SCRIPTS',"presets/",create=True)
# Move the content of
# source to destination
# print("Dest %s" % os.path.isdir(os.path.join(destination,cwppFold)))
destPath = os.path.isdir(os.path.join(destination,cwppFold))
try:
# dest = shutil.move(source, destination, copy_function = shutil.copytree(source, destination,dirs_exist_ok=False))
# dest = shutil.move(source, destination, copy_function=shutil.copy2) # copy_function = shutil.copytree(source, destination,dirs_exist_ok=False))
print(source)
print(os.path.isdir(source))
if os.path.isdir(source) or destPath:
dest = shutil.move(source, destination, copy_function = shutil.copytree)
if dest:
print("Weight Paint presets installed")
else:
print("Weight Paint Preset already installed")
except Error:
print("Issue Save-Custom-WeightPaint_presets \n %s" % Error)
def brush_weight_paint(self, context):
'''
bpy.ops.paint.weight_paint_toggle()
PAINT_OT_BRUSH_SELECT.weight_tool()
'''
layout = self.layout
tool_mode = context.mode
layout.use_property_split = True
layout.use_property_decorate = False
tool_settings = context.tool_settings
wpaint = tool_settings.weight_paint
if tool_mode == 'PAINT_WEIGHT':
col = layout.column()
sub = col.split()
sub.separator()
sub.operator("paint.brush_select", text="Draw").weight_tool='DRAW'
sub.operator("paint.brush_select", text="Blur").weight_tool='BLUR'
sub.operator("paint.brush_select", text="Average").weight_tool='AVERAGE'
sub.operator("paint.brush_select", text="Smear").weight_tool='Smear'
# sub.operator("paint.brush_select", text="Gradient").weight_tool='GRADIENT'
def tool_weight_paint_presets(self, context):
layout = self.layout
tool_mode = context.mode
layout.use_property_split = True
layout.use_property_decorate = False
tool_settings = context.tool_settings
wpaint = tool_settings.weight_paint
if tool_mode == 'PAINT_WEIGHT':
col = layout.column()
row = col.split(factor=0.33)
row.label(text="Weightpaint")
sub = row.row()
sub.menu("SCWPP_PREFS_MT_weight_paint_presets",
text=bpy.types.SCWPP_PREFS_MT_weight_paint_presets.bl_label)
def ui_weight_paint_presets(self, context):
layout = self.layout
width = context.region.width
prefs = context.preferences
ui_scale = prefs.system.ui_scale
# No horizontal margin if region is rather small.
is_wide = width > (350 * ui_scale)
layout.use_property_split = True
layout.use_property_decorate = False # No animation.
if prefs.view.use_weight_color_range:
layout.separator()
row = layout.row()
if is_wide:
row.label() # Needed so col below is centered.
col = row.column()
col.ui_units_x = 50
sub = col.row(align=True)
# sub.label(text="Presets")
sub.menu("SCWPP_PREFS_MT_weight_paint_presets",
text=bpy.types.SCWPP_PREFS_MT_weight_paint_presets.bl_label)
sub.operator("preferences.weight_paint_preset_add", text="", icon="ADD")
sub.operator("preferences.weight_paint_preset_add",
text="", icon="REMOVE").remove_active = True
if is_wide:
row.label() # Needed so col above is centered.
def register():
# bpy.utils.register_class(CenterAlignMixIn)
bpy.utils.register_class(SCWPP_AddPresetWeightPaint)
bpy.utils.register_class(SCWPP_PREFS_MT_weight_paint_presets)
bpy.types.USERPREF_PT_edit_weight_paint.append(ui_weight_paint_presets)
bpy.types.VIEW3D_PT_paint_weight_context_menu.append(brush_weight_paint)
bpy.types.VIEW3D_PT_overlay_weight_paint.append(tool_weight_paint_presets)
bpy.types.VIEW3D_PT_tools_weightpaint_options.append(tool_weight_paint_presets)
install_presets()
def unregister():
# bpy.utils.unregister_class(CenterAlignMixIn)
bpy.utils.unregister_class(SCWPP_AddPresetWeightPaint)
bpy.utils.unregister_class(SCWPP_PREFS_MT_weight_paint_presets)
bpy.types.USERPREF_PT_edit_weight_paint.remove(ui_weight_paint_presets)
bpy.types.VIEW3D_PT_paint_weight_context_menu.remove(brush_weight_paint)
bpy.types.VIEW3D_PT_overlay_weight_paint.remove(tool_weight_paint_presets)
bpy.types.VIEW3D_PT_tools_weightpaint_options.remove(tool_weight_paint_presets)