0

Here in this task I am trying to add some QC Validation in blender, where my objective is once clicking the operator button if it passes QC Validation then the button turns green otherwise it turns red.

I have Python script where I am trying to add this sample logic in operator Mesh Count QC, so my mesh_count_operator should be something like this following pseudocode

class MeshCountOperator(bpy.types.Operator):
    bl_idname = "object.mesh_count_operator"
    bl_label = "Mesh Count Operator"
    count = len(bpy.context.scene.objects)        
    if count > 5:
        set Mesh Count Operator -> green
    else:
        set Mesh Count Operator -> red

My python script is as follows:

import bpy

class AssetOperator(bpy.types.Operator): bl_idname = "object.my_operator" bl_label = "Asset Operator"

def execute(self, context):
    return {'FINISHED'}

def invoke(self, context, event):
    return context.window_manager.invoke_props_dialog(self, width=200)

def draw(self, context):
    layout = self.layout
    layout.operator("mesh.primitive_cube_add", text="Asset Tool 1")
    layout.operator("mesh.primitive_cone_add", text="Asset Tool 2")


class MeshQCOperator(bpy.types.Operator): bl_idname = "object.mesh_qc_operator" bl_label = "Mesh QC Operator"

def execute(self, context):
    return {'FINISHED'}

def invoke(self, context, event):
    return context.window_manager.invoke_props_dialog(self, width=200)

def draw(self, context):
    layout = self.layout
    layout.operator("mesh.primitive_cube_add", text="Mesh Geo QC")
    layout.operator("mesh.mesh_count_operator", text="Mesh Count QC")


class AssetQCOperator(bpy.types.Operator): bl_idname = "object.asset_qc_operator" bl_label = "Asset QC Operator"

def execute(self, context):
    return {'FINISHED'}

def invoke(self, context, event):
    return context.window_manager.invoke_props_dialog(self, width=200)

def draw(self, context):
    layout = self.layout
    row = layout.row()
    row.operator("object.mesh_qc_operator", text="QC Validation")
    row.operator("object.mesh_qc_operator", text="Publish Asset")


class TOPBAR_MT_custom_sub_menu_1(bpy.types.Menu): bl_label = "Publish Tools"

def draw(self, context):
    layout = self.layout
    layout.operator("object.asset_qc_operator", text="Asset QC")


class TOPBAR_MT_custom_sub_menu_2(bpy.types.Menu): bl_label = "Asset Tools"

def draw(self, context):
    layout = self.layout
    layout.operator("object.my_operator", text="Asset Tools")


class TOPBAR_MT_custom_menu(bpy.types.Menu): bl_label = "Zas Tools"

def draw(self, context):
    layout = self.layout
    layout.menu("TOPBAR_MT_custom_sub_menu_1")
    layout.menu("TOPBAR_MT_custom_sub_menu_2")

def menu_draw(self, context):
    self.layout.menu("TOPBAR_MT_custom_menu")


classes = (TOPBAR_MT_custom_menu, TOPBAR_MT_custom_sub_menu_1, TOPBAR_MT_custom_sub_menu_2, AssetQCOperator, MeshQCOperator, AssetOperator)

def register(): for cls in classes: bpy.utils.register_class(cls) bpy.types.TOPBAR_MT_editor_menus.append(TOPBAR_MT_custom_menu.menu_draw)

def unregister(): bpy.types.TOPBAR_MT_editor_menus.remove(TOPBAR_MT_custom_menu.menu_draw) for cls in classes: bpy.utils.unregister_class(cls)

if name == "main": register()

Is it possible to achieve this functionality or I need to go with some other ways to let user know about the QC status.I have done similar process in maya using pyside/pyqt but I am quite new to blender scripting so any reference would be really helpful as well.

2 ) Also one more thing is there any way to add a refresh button as well, so for example i have 3 objects in blender scene , i clicked on the qc operator it turns red(as it will fail according to the logic), but then add few extra objects and now the number is greater than 5, so rather than re-doing all process i can directly change the status of the operator using the refresh button.

Thanks & Regards

  • Hello ! It seems you can't change the text color using the python API. You can however change the field background color to red if you use the alert flag https://blender.stackexchange.com/a/8861/86891 but that's as much customization as you'll be able to afford. Another solution is to use a custom shader using the gpu module but that's another nut to crack – Gorgious May 10 '23 at 14:49
  • Okay okay got it, do you have any reference to the gpu source tho where i can learn a bit about them, also any input of yours on the second part of the question as well please. Thanks – madara_was_right May 10 '23 at 14:56
  • it's pretty sparsely documented unfortunately, and the previous way to draw text on screen was phased out in the last versions... Try "blender python gpu text screen space" as keywords in your search engine of choice. On this site you should ask only one question per thread, would you mind opening a new question to ask it ? – Gorgious May 10 '23 at 15:06
  • Thanks and sure I'll open a new question . – madara_was_right May 10 '23 at 15:10

0 Answers0