0
$\begingroup$

I created a new startup file+script for low-poly 3D modeling for my game project. Basically a default cube with origin on the "floor" and a custom material. The script sets up my preferred editor settings (inspired by https://www.youtube.com/watch?v=1jHUY3qoBu8) but there's just one problem...

I can't seem to enable the move gizmo from the startup script.

move gizmo not getting enabled on startup

Here's the code:

import bpy

def setup_material():
    bpy.data.materials['Material'].node_tree.nodes['Image Texture'].image.filepath_raw = "/home/gk/Desktop/gamedev/projects/shooter/textures/simple_palette.png"
    bpy.data.materials['Material'].node_tree.nodes['Image Texture'].image.reload()

def setup_viewport():
    bpy.context.window.workspace = bpy.data.workspaces['UV Editing']
    for area in bpy.context.screen.areas:
        if area.type == 'VIEW_3D':
            for space in area.spaces:
                if space.type == 'VIEW_3D':
                    space.shading.type = 'SOLID'
                    space.shading.color_type = 'TEXTURE'
                    space.shading.show_backface_culling = True
                    space.shading.show_cavity = True
                    space.shading.cavity_type = 'BOTH'
                    space.shading.cavity_ridge_factor = 2.5
                    space.shading.cavity_valley_factor = 2.5
                    space.shading.show_shadows = True
                    space.show_gizmo = True
                    space.show_gizmo_tool = True
                    space.show_gizmo_context = True
                    space.show_gizmo_object_translate = True

def register():
    setup_material()
    setup_viewport()


def unregister():
    pass

How can I enable the move gizmo from the startup script? I'm trying every possible way of doing it, but it's not working.

$\endgroup$

1 Answer 1

0
$\begingroup$

The actual solution for saving UI settings is to set them and save a startup file - File -> Defaults -> Save Startup File however if one wanted to run a startup script changing the UI, one could enable Python Tooltips in the preferences to see what buttons in the UI do:

enter image description here

or change something and see logged commands in the Info editor:

enter image description here

It also seems that startup scripts have limited context when they run, so you need to put whatever code you want to run in an app handler so it runs after loading a file:

import bpy
from bpy.app.handlers import persistent

@persistent
def load_handler(dummy):
    for area in bpy.context.screen.areas:
        if area.type == 'VIEW_3D':
            for space in area.spaces:
                if space.type == 'VIEW_3D':
                    space.shading.type = 'SOLID'
                    space.shading.color_type = 'TEXTURE'
                    space.shading.show_backface_culling = True
                    space.shading.show_cavity = True
                    space.shading.cavity_type = 'BOTH'
                    space.shading.cavity_ridge_factor = 2.5
                    space.shading.cavity_valley_factor = 2.5
                    space.shading.show_shadows = True
                    space.show_gizmo = True
                    space.show_gizmo_tool = True
                    space.show_gizmo_context = True
                    space.show_gizmo_object_translate = True


def register():    
    bpy.app.handlers.load_post.append(load_handler)
        
def unregister():
    bpy.app.handlers.load_post.remove(load_handler)
$\endgroup$
9
  • $\begingroup$ That's incredibly useful! Thanks! $\endgroup$
    – gulagkulak
    Commented Sep 25, 2023 at 7:51
  • $\begingroup$ Talking about incredibly useful stuff when scripting in Blender - you know about auto-complete(tab) functionality in the Python Console, right? It's also very helpful when you want to explore the API. $\endgroup$ Commented Sep 25, 2023 at 7:57
  • $\begingroup$ I did not know that autocomplete worked in the scripting tab, lol. I've been using the good old dir(object) to introspect and the Blender API docs :D $\endgroup$
    – gulagkulak
    Commented Sep 25, 2023 at 8:04
  • $\begingroup$ @MartynasŽiemys but the querent already has the solution in his code space.show_gizmo_object_translate = True which already works, so I'm confused if this post solved his problem? Nevertheless it presents some useful information for the OP and the community. $\endgroup$
    – Harry McKenzie
    Commented Sep 25, 2023 at 11:25
  • 1
    $\begingroup$ That's true, it's confusing. I missed it, but I did test it before posting the answer and it does work. $\endgroup$ Commented Sep 25, 2023 at 11:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .