1 # SPDX-License-Identifier: GPL-2.0-or-later
5 get_addon_name
= 'space_view3d_brush_menus'
11 # check for (currently) brushes being linked
12 def get_brush_link(context
, types
="brush"):
13 tool_settings
= context
.tool_settings
16 if get_mode() == 'SCULPT':
17 datapath
= tool_settings
.sculpt
19 elif get_mode() == 'VERTEX_PAINT':
20 datapath
= tool_settings
.vertex_paint
22 elif get_mode() == 'WEIGHT_PAINT':
23 datapath
= tool_settings
.weight_paint
25 elif get_mode() == 'TEXTURE_PAINT':
26 datapath
= tool_settings
.image_paint
31 has_brush
= getattr(datapath
, "brush", None)
38 # separate function just for more convenience
39 addon
= bpy
.context
.preferences
.addons
[get_addon_name
]
40 colum_n
= addon
.preferences
.column_set
if addon
else 1
45 def error_handlers(self
, op_name
, error
, reports
="ERROR", func
=False):
47 self
.report({'WARNING'}, reports
+ " (See Console for more info)")
49 is_func
= "Function" if func
else "Operator"
50 print("\n[Sculpt/Paint Brush Menus]\n{}: {}\nError: {}\n".format(is_func
, op_name
, error
))
54 # 'OBJECT' 'EDIT' 'SCULPT'
55 # 'VERTEX_PAINT' 'WEIGHT_PAINT' 'TEXTURE_PAINT'
56 # 'PARTICLE_EDIT' 'POSE' 'GPENCIL_EDIT'
58 return bpy
.context
.object.mode
60 def menuprop(item
, name
, value
, data_path
,
61 icon
='NONE', disable
=False, disable_icon
=None,
62 custom_disable_exp
=None, method
=None, path
=False):
68 # used if you need a custom expression to disable the ui
69 if custom_disable_exp
:
70 if custom_disable_exp
[0] == custom_disable_exp
[1]:
74 # check if the ui should be disabled for numbers
75 elif isinstance(eval("bpy.context.{}".format(data_path
)), float):
76 if round(eval("bpy.context.{}".format(data_path
)), 2) == value
:
80 # check if the ui should be disabled for anything else
82 if eval("bpy.context.{}".format(data_path
)) == value
:
86 # change the icon to the disable_icon if the ui has been disabled
87 if disable_icon
and disabled
:
90 # creates the menu item
91 prop
= item
.operator("wm.context_set_value", text
=name
, icon
=icon
)
93 # sets what the menu item changes
98 elif type(value
) == str:
99 prop
.value
= "'{}'".format(value
)
102 prop
.value
= '{}'.format(value
)
104 # sets the path to what is changed
105 prop
.data_path
= data_path