How to toggle the new transform gizmos using python

I’m trying toggle the transform overlays using python, but I can’t seem to get it to work. I think it’s a context issue, but I’m not sure. When you toggle the move gizmo, this comes up in the info window:

bpy.context.space_data.show_gizmo_object_translate = True

I can’t roll this into my own scripts though.

I’m in the process of putting the gizmo popover, and a few others like interaction mode and object select/visibility, into their own menu in the 3d header. I know that making an operator class for every single item isn’t the most elegant way to do it, but it works fine.

It doesn’t do anything, but it does toggle the option inside the popover. So whatever it’s supposed to do is being done I guess. Show_gizmo, the one that toggles everything, makes the translate gizmo show/hide. So maybe something goofy right now or I don’t understand what it is supposed to be for. Everything else works like it should though, like navigate.

class VIEW3D_gizmo_translate(bpy.types.Operator):
    """Show Translate Gizmo"""
    bl_idname = "view3d.gizmotranslate"
    bl_label = "Showgizmotranslate Operator"

def execute(self, context):
    space = context.space_data
    if space.show_gizmo_object_translate == True:
        space.show_gizmo_object_translate = False
        space.show_gizmo_object_translate = True

1 Like

Hi Icas. A little python trick for toggling a property is using the ^= characters. For instance, you can replace:

if space.show_gizmo_object_translate == True:
        space.show_gizmo_object_translate = False
        space.show_gizmo_object_translate = True

with a single line like this:


I managed to work out what I was looking for today. I wanted to be able to toggle each of the transform gizmos using the keyboard instead of having to go into the Viewport Gizmos dropdown. I did this as an exercise and proof of concept for the Industry Compatible Keymap task. The addon I created as well as the modified keymap are on my github. The issue I was having when I created this thread was that I needed to get the context of each 3d View to be able to activate the gizmo in all of them. I did so by going through every area in the active screen and seeing if it’s a 3d View and then toggling the show_gizmo_object_… properties using the trick I showed you above:

    import bpy

    areas = bpy.context.workspace.screens[0].areas

    for area in areas:
        for space in area.spaces:
            if space.type == 'VIEW_3D':
                space.show_gizmo_object_translate^= True



Thanks, going to save a lot of lines with that one

Thanks it seems help me a lot too.

I really wanted to be able to just edit the ICK so that WER would work like this, but I guess there is no way around it without custom operators. :confused:

Thanks for linking your repo, starred it.

Yeah that really put me off as well. Hopefully they will make it so that it can be easily be added to the keymap.