I’m trying to build a small addon with a single 2d gizmo button. The code works as expected when it is enabled (or disabled and re-enabled) in preferences, clicking the button executes indicated operator. However, when the preferences are saved to have the addon automatically started with blender, when Blender starts, the button doesn’t react at all on any user actions. The only solution - to disable and re-enable addon in preferences. Then the button works again… And when the Blender is restarted… Again it is needed to disable and re-enable addon…
Sample code:
# Licensing information
bl_info = {
"name": "Gizmo button 2d test",
"version": (0, 1),
"blender": (2, 80, 0),
"description": "test gizmo button 2d functionality, report problem...",
"location": "View3D",
"warning": "",
"category": "3D View"
}
import bpy
from bpy.props import (IntProperty, EnumProperty, BoolProperty)
from bpy.types import (AddonPreferences, GizmoGroup, Operator)
class GizmoButton2D(GizmoGroup):
""" test gizmo button 2d """
bl_idname = "view3d.gizmo_button_2d"
bl_label = "Test button 2d"
bl_space_type = 'VIEW_3D'
bl_region_type = 'WINDOW'
bl_options = {'PERSISTENT', 'SCALE'}
@classmethod
def poll(cls, context):
if context.object != None:
return True
return False
def draw_prepare(self, context):
self.foo_gizmo.matrix_basis[0][3] = 100
self.foo_gizmo.matrix_basis[1][3] = 100
def setup(self, context):
mpr = self.gizmos.new("GIZMO_GT_button_2d")
mpr.target_set_operator("transform.rotate")
mpr.icon = 'OUTLINER_OB_CAMERA'
mpr.draw_options = {'BACKDROP', 'OUTLINE'}
mpr.alpha = 0.0
mpr.color_highlight = 0.8, 0.8, 0.8
mpr.alpha_highlight = 0.2
mpr.scale_basis = (80 * 0.35) / 2 # same as buttons defined in C
self.foo_gizmo = mpr
def register():
bpy.utils.register_class(GizmoButton2D)
def unregister():
bpy.utils.unregister_class(GizmoButton2D)
Any ideas? I’m really stuck, everything I’ve tried doesn’t change anything. Do I miss something? Is there a difference when addon is started by enabling it in Preferences or being automatically loaded by Blender?..
Update:
The last Blender build reports warnings on empty keymap for the newly created GizmoButton2D. I’ve tried to provide
def setup_keymap(cls, keyconfig):
keymap = ...
return keymap
however I don’t know how to correctly populate the keymap. And after this modification the button doesn’t work even after disabling and re-enabling addon…