Trigger Multiple Items In One Button

Hello All!
I have recently started using the blender python and have pretty much no experience ever using it! I am in some complex stuff but have been working out a lot by myself! One thing I have been stuck on is triggering multiple things to happen when I press one button. What I am trying to do is change all of the rotation properties from a ‘child of’ constraint from on to off with one button. I am struggling to figure it out though! I am currently stuck with 3 buttons that change one of the properties each

Any help is appreciated!

-UtopiaRules

you can either create an operator and set a bunch of properties in its execute() method, or use a BoolProperty with an update-callback that changes certain other things every time it is toggled.

Hi CoDEmanX
I am very new to coding so have nooooo clue what this means. I thought that maybe it would be easier than that! I managed to do it with custom properties but that is now a slider but I would prefer it to be a button!

Thanks for trying to help though

-UtopiaRules

Here’s an example:

import bpy

class SimplePanel(bpy.types.Panel):
    bl_idname = "OBJECT_PT_sample"
    bl_label = "Sample Panel"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"
    
    def draw(self, context):
        layout = self.layout
        layout.operator(SimpleOperator.bl_idname)


class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"

    def execute(self, context):
        ob = context.object
        ob.show_name = not ob.show_name
        ob.show_axis = not ob.show_axis
        ob.show_wire = not ob.show_wire
        ob.show_all_edges = not ob.show_all_edges
        return {'FINISHED'}

def register():
    bpy.utils.register_module(__name__)

def unregister():
    bpy.utils.unregister_module(__name__)

if __name__ == "__main__":
    register()


Run it in the Text Editor and see the Object tab. Click the button to toggle a few object display settings.

Thanks That worked! However the button doesn’t stay pressed down like a normal toggle would. Would you know how to do that where it looks like a normal toggle instead of one that when you push it it looks the same? Such as it is either On or Off?

Thanks for the coding help Anyway!

-UtopiaRules

buttons don’t have a state, you need to use a bool property:

import bpy

class SimplePanel(bpy.types.Panel):
    bl_idname = "OBJECT_PT_sample"
    bl_label = "Sample Panel"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"
    
    def draw(self, context):
        layout = self.layout
        wm = context.window_manager
        layout.prop(wm, "my_toggle", toggle=True)


def upd(scene, context):
    ob = context.object
    ob.show_name = not ob.show_name
    ob.show_axis = not ob.show_axis
    ob.show_wire = not ob.show_wire
    ob.show_all_edges = not ob.show_all_edges


def register():
    bpy.utils.register_module(__name__)
    bpy.types.WindowManager.my_toggle = bpy.props.BoolProperty(
        update=upd
    )

def unregister():
    bpy.utils.unregister_module(__name__)
    del bpy.types.WindowManager.my_toggle

if __name__ == "__main__":
    register()

But note that there’s no two-way binding of the properties the callback function toggles.

Ok Thanks for the script!! Also Thanks for all the help and stuffs!!

-UtopiaRules

Oooo! Hopefully this is the last question but how do I get two of these on the same row? Just wondered because thats how I wanted to do it!

See the panel templates in the text editor and also here:

http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/Code_snippets/Interface#Panel_layout_and_several_arguments

Hi Again! Just wondered how I could get the button to remember its state when i reopen the file? Because i have a toggle that switches whether the arm follows or doesn’t follow the chest bone in IK mode however if I leave the button on when i close the file, when I reopen the file it is off with the same properties selected so it ends up inverted.

Any help?

-UtopiaRules

it’s not that easy, see