I am developing an add-on, which only works if some specific conditions are satisfied (e.g. some other add-on is installed). Hence, I want the user to be unable to register this add-on if the conditions are not satisfied.
I thought I can ensure the conditions during the register()
function. If the conditions are not satisfied, I want Blender to cancel the add-on registering, while displaying a message, saying what the user has to do.
I figured out how to display the message following https://blender.stackexchange.com/a/118183/117198
def display_error(message):
display_text = lambda self, context: self.layout.label(text = message)
bpy.context.window_manager.popup_menu(display_text, title='Error', icon='ERROR')
However, I don't know how to properly cancel the add-on registering. I figured that raising an error would cancel registering, but it displays the traceback, which is not user-friendly.
def register():
if not my_conditions:
raise Exception("The conditions were not met.")
else:
# Continue register
Traceback (most recent call last):
File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\modules\addon_utils.py", line 382, in enable
mod.register()
File "C:\Users\VirtualUser\AppData\Roaming\Blender Foundation\Blender\2.90\scripts\addons\my_addon.py", line 116, in register
raise Exception("The conditions were not met.")
Exception: The conditions were not met.
Is there a proper way to cancel add-on registering? Alternatively, is there a way to hide the traceback?
if not my_conditions: pass else: register()
$\endgroup$ – Gorgious Feb 25 at 12:52bpy.ops.preferences.addon_disable(module="module_name")
, but you can't call it fromregister
function. Best I can think of is running this when you try to use the addon, but don't meet the required condition. $\endgroup$ – Roki Podpecan Feb 28 at 21:06