Skip to content

Instantly share code, notes, and snippets.

@SuddenDevelopment
Created December 23, 2022 12:39
Show Gist options
  • Select an option

  • Save SuddenDevelopment/0ec0317ce7a3221a68c8234280fd63ea to your computer and use it in GitHub Desktop.

Select an option

Save SuddenDevelopment/0ec0317ce7a3221a68c8234280fd63ea to your computer and use it in GitHub Desktop.
blender python ui gizmo POC, does NOT work with custom icons
from bpy.types import (
GizmoGroup
)
import bpy
bl_info = {
"name": "POC buttons",
"description": "POC 2D BUTTON script refactored from GP Animator Desk addon",
"author": "Anthony Aragues, P.Świda",
"version": (0, 0, 1),
"blender": (3, 4, 0),
"location": "3d window",
"wiki_url": "",
"tracker_url": "",
"category": "UI"
}
class POC_UI_Buttons(GizmoGroup):
bl_idname = "POC UI Buttons"
bl_label = "POC UI Buttons"
bl_space_type = 'VIEW_3D'
bl_region_type = 'WINDOW'
bl_options = {'PERSISTENT', 'SCALE'}
@classmethod
def poll(cls, context):
# modify this to whatever conditions you need for showing this gizmo group
return True
def draw_prepare(self, context):
# set the x and y for the gizmo, by default starting from bottom left == the center of the gizmo
intGizmoSize = 70
intTotalSize = 0
intGizmoCount = 0
for strGizmo in self.objGizmos:
intGizmoCount += 1
intTotalSize += intGizmoSize
for i, strGizmo in enumerate(self.objGizmos):
objGizmo = getattr(self, strGizmo)
intX = (context.region.width/2) - \
(intTotalSize/2) + (intGizmoSize*i)
objGizmo.matrix_basis[0][3] = intX
objGizmo.matrix_basis[1][3] = 43
return
def setup(self, context):
objGizmoDefaults = {
"color": (1, 0, 0),
"color_highlight": (0, 0, 1),
"show_drag": False,
"scale_basis": 15.5,
"alpha": 0.8,
"draw_options": {'BACKDROP', 'OUTLINE'},
"icon": 'BLENDER',
"use_tooltip": True
}
self.objGizmos = {
"insert_btn": {
"icon": 'FUND'
},
"remove_btn": {
"icon": 'COPY'
}
}
for strGizmo in self.objGizmos:
# create the new gizmo
objGizmo = self.gizmos.new("GIZMO_GT_button_2d")
# start it with some defaults
for strProp in objGizmoDefaults:
setattr(objGizmo, strProp, objGizmoDefaults[strProp])
# override the defaults
for strProp in self.objGizmos[strGizmo]:
setattr(objGizmo, strProp, self.objGizmos[strGizmo][strProp])
# attach the gizmo to 'self'
setattr(self, strGizmo, objGizmo)
def register():
bpy.utils.register_class(POC_UI_Buttons)
def unregister():
bpy.utils.unregister_class(POC_UI_Buttons)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment