Checkbox

Hi everybody,
I wonder how to make a checkbox inside the tool panel.

I need to check a boolean to delete or not the objects selection after the execution of an operator.

I’m a newbie to python and to blender 2.5 scripting and I dont’ know how to do this simple thing. I haven’t found nothing on the forum to help me to understand. I tried to take a look on the scripts under the ui folder but I don’t get the logic behind that code.

Thank you for your help

Here’s an example:

import bpy
from bpy.props import BoolProperty

# add your custom property to the Scene tpye
bpy.types.Scene.my_prop = BoolProperty(
    name="Prop name",
        description="Some tooltip",
        default = True)
        
# your custom panel
class MyPanel(bpy.types.Panel):
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "render"        # where it will appear (render, world, material...)
    bl_label = 'My custom panel'
    
    @classmethod
    def poll(self, context):
        return True
        
    def draw(self, context):
        layout = self.layout
        sce = context.scene
        # draw the checkbox (implied from property type = bool)
        layout.prop(sce, "my_prop") 

# must register the panel
bpy.utils.register_class(MyPanel)


In your operator just query what is the value of bpy.context.scene.my_prop

1 Like

Hiya… another way to do it is using the popup dialogs available with the operator… especially if the property is operator specific. Here is an example for cleaning fcurves… i stuck in a boolean checkbox for context re your question. This way whenever you have a panel that uses that operator you get the option.


import bpy, mathutils
import bpy.ops
from bpy.props import *

class CleanFCurvePanel(bpy.types.Panel):
    bl_label = "Clean Fcurve"
    bl_space_type = "GRAPH_EDITOR"
    bl_region_type = "UI"

    def draw(self, context):
        layout = self.layout


        layout.operator("fcurve.cleaner")

    @classmethod 
    def poll(self,context):

        return True

class FCurveCleaner(bpy.types.Operator):
    bl_idname = "fcurve.cleaner"
    bl_label = "Clean FCurve"
    threshold = FloatProperty("threshold",default=0.001,description="Threshold for the clean operator",min=0.001,max=0.1,precision=3)
    flag = BoolProperty("flag",default=False,description="Do something if flagged")
    #self.threshold = 0.001
    
    def invoke(self, context, event):
        wm = context.window_manager
        return wm.invoke_props_dialog(self)

    def draw(self,context):
        layout = self.layout
        layout.prop(self,"threshold")
        layout.prop(self,"flag",text="Do Something")
  
    def execute(self, context):
        print(self.threshold)
        bpy.ops.graph.clean(threshold=self.threshold)
        self.report("INFO","FCurve Cleaned")     
        return{'FINISHED'}
     
def register():
    bpy.utils.register_class(CleanFCurvePanel)
    bpy.utils.register_class(FCurveCleaner)


def unregister():
    bpy.utils.unregister_class(CleanFCurvePanel)    
    bpy.utils.unregister_class(FCurveCleaner)
print(__name__)
if __name__ in ["__main__","cleanfcurve"]:
    register() 

btw if you want your panel in the TOOLS of the 3d view change to


    bl_space_type = "VIEW_3D" 
    bl_region_type = "TOOLS" 

or in the operator properties section below the tools


   bl_region_type = "TOOL_PROPS"

Thank you all guys!!!

tested last script but

got it almost working in tool propr panel

but get error on fcurve

does it means you need to have at least one f curve or IPO to have it find one may be?

and do you get the pop up to pop up ?
is it key activated and which one?

Thanks happy 2.5

The panel is in the properties “n” section of the graph editor… To make the popup “pop up” hit the button.

11 years later and this still helped, tysm brother