I’ve created a boolean property to be used in a panel. But I only know how to use it to set an option which can then be later executed in the script somewhere else. How would I use the BoolProperty to execute my chosen functions as soon as it’s pressed?
In the code below, I need the “def execute(self,context):” section to be executed as soon as the bool is pressed or unpressed. Thanks for any help or ideas.
class optionsButtons(bpy.types.Operator):
bl_idname = "object.options_buttons"
bl_label = "Button"
bpy.types.WindowManager.myBool = bpy.props.BoolProperty(name = "My Bool",
description = "", default = False)
def execute(self, context):
if bpy.context.window_manager.myBool == True:
#Do some stuff for if the button is pressed.
else:
#Do some stuff when the button is released.
Ok, maybe I worded this a bit confusingly. Can anyone show me how to properly use a BoolProperty such that I can direct it’s true and false states to execute separate functions?
It’s not working. The bool is working, the info screen console (not the headline information that would be displaying if it were working) displays the property as true or false when pressed and it looks like it’s being pressed on the screen, it’s just not executing the if statement. Here’s the full code. Am I missing some gears here?
import bpy
class optionsButtons(bpy.types.Operator):
bl_idname = "object.options_buttons"
bl_label = "Button"
bl_options = {'REGISTER', 'UNDO'}
bpy.types.WindowManager.myBool = bpy.props.BoolProperty(name = "My Bool",
description = "", default = False)
def execute(self, context):
if bpy.context.window_manager.myBool == True:
self.report({'INFO'}, "I am True")
else:
self.report({'INFO'}, "I am False")
class myPanel(bpy.types.Panel):
bl_label = "My Panel"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
def draw(self, context):
layout = self.layout
row = layout.row()
row.prop(context.window_manager, "myBool")
def register():
bpy.utils.register_module(__name__)
def unregister():
bpy.utils.unregister_module(__name__)
if __name__ == "__main__":
register()
You can’t access it from the panel, you need another property (global) for that.
How would I do that? That’s the whole reason I posted this thread. I don’t understand how to make a bool execute as it is checked or unchecked. I came across a tutorial once that explained it but for the life of me I can’t seem to remember what it was called. I have no idea how to apply the code you provided to my problem.