Category: Blender

Rotate and Scale Don’t Work in Blender

This is trouble shooting.

Problem

I couldn’t resize or rotate widget in Blender.

example) expanding box in the x-axis direction

Environment

Blender 2.83
Windows 10

Check List

Affect Only check box

If the Options > Affect Only > Locations checkbox is on, check it off.

Transform is rocked

If the Rotation and Scale are rocked, the arrows to resize or rotate are not displayed.

How To Use Keymap Preference in Blender

The system of keymap preference in Blender is complex a little.

GOAL

Today’s goal is to summarize how to customize keymaps in Blender. The main contents are how to change keymaps, save and import/export key configuration presets. This article doesn’t contain how to use keymap editor or details of UI.

Environment

Blender 2.83 (Python 3.7.4)
Windows 10

What is keymap preference?

The following is an excerpt from the Blender manual.

The keymap editor lets you adjust your keymap via:

Presets: Predefined keymaps which come with Blender and can be added to.
Preferences: Keymaps may define their own preferences to change the functionality or add additional key bindings.
Key Map Items: You may add/remove/edit individual keymap entries.

from “Keymap” in Blender 2.92 Manual

How to change keymap

Keymaps can be changed in each keymap editor.

(more…)

How to get keyconfig object with its path in Blender Python

This is a part of the project “Easy Keymap Generator”.

GOAL

To implement a function that get keyconfig name and return keyconfig object.

The list of keyconfig names can be seen in Preferences window.

Environment

Blender 2.83 (Python 3.7.4)
Windows 10

Method

This is my solution, but I don’t think it is the best way. Please let me know if you have any better ideas.

1 Access bpy.context.window_manager.keyconfigs

def get_keyconfig(keyconfig_name):
    wm = bpy.context.window_manager
    if keyconfig_name in wm.keyconfigs.keys():
        return wm.keyconfigs[keyconfig_name]
    else:
        return None

2 Activate specified keyconfig and return active keyconfig

If there is no keyconfig you’d like to get in current environment, you should activate the keyconfig by its path manually.

key_config_dict = get_keyconfig_dict()
configs = list(key_config_dict.keys())
print(configs) 
# output => ['blender', 'blender_27x', 'industry_compatible', 'test1', 'test2']

kc = get_keyconfig(configs[1], key_config_dict)
print(kc) 
# output => blender_27x <bpy_struct, KeyConfig("blender_27x")>

2.1 Get keyconfigs and paths to the keyconfig file.

I created a function to get the dict with keys of keyconfig name and values of path to the keyconfig python file.
Reference: How to get key config list in Blender Python

def get_keyconfigs():
    """
    :return: dict{kerconfig_name(str): path to config file(str)}
    """
    config_pathes = bpy.utils.preset_paths("keyconfig")
    config_dict = {}
    for config_path in config_pathes:
        for file in os.listdir(config_path):
            name, ext = os.path.splitext(file)
            if ext.lower() in [".py", ".xml"] and not name[0] == ".":
                config_dict[name] = os.path.join(config_path, file)
    return config_dict

2.2 Activate specified keyconfig and return active keyconfig

Activate the specified keyconfig by its path and get active keyconfig with wm.keyconfigs.active then restore active keyconfig to original settings.

def get_keyconfig(keyconfig_name, keyconfig_dict):
    wm = bpy.context.window_manager
    if keyconfig_name in wm.keyconfigs.keys(): #if the keyconfig can be found, return it
        return wm.keyconfigs[keyconfig_name]
    else: # activate by config path and return it
        keyconfig_path = keyconfig_dict[keyconfig_name]
        current_path = keyconfig_dict[wm.keyconfigs.active.name]
        bpy.ops.preferences.keyconfig_activate(filepath=keyconfig_path)
        kc = wm.keyconfigs.active
        bpy.ops.preferences.keyconfig_activate(filepath=current_path)
        return kc

How to get key config list in Blender Python

This is a part of the project “Easy Keymap Generator”.

GOAL

To get the key config list in my addon. The list of key configs can be seen in Preferences window.

Environment

Blender 2.83 (Python 3.7.4)
Windows 10

Method

Get the list directly from the preset directories.
Related article: How to get preset paths in Blender Python

def get_keyconfigs():
    """
    :return: dict{kerconfig_name(str): path to config file(str)}
    """
    config_pathes = bpy.utils.preset_paths("keyconfig")
    config_dict = {}
    for config_path in config_pathes:
        for file in os.listdir(config_path):
            name, ext = os.path.splitext(file)
            if ext.lower() in [".py", ".xml"] and not name[0] == ".":
                config_dict[name] = os.path.join(config_path, file)
    return config_dict

print(key_config_dict.keys())
#output => dict_keys(['blender', 'blender_27x', 'industry_compatible', 'test1', 'test2'])

How to get preset paths in Blender Python

This is a tips for blender addon developers.

GOAL

To get the list of paths to preset directories, blender system preset and user preset and so on.

These are examples of the preset directory.

  • presets of interface theme
    • C:\Program Files\Blender Foundation\Blender 2.83\2.83\scripts\presets\interface_theme
    • C:\Program Files\Blender Foundation\Blender 2.83\2.83\scripts\addons\presets\interface_theme’
  • presets of keyconfig
    • C:\Program Files\Blender Foundation\Blender 2.83\2.83\scripts\presets\keyconfig
    • C:\Users\<USER_NAME>\AppData\Roaming\Blender Foundation\Blender\2.83\scripts\presets\keyconfig

Environment

Blender 2.83 (Python 3.7.4)
Windows 10

Method

Use bpy.utils.preset_paths(subdir) that returns the list of paths to the preset directory of subdir.

(more…)

How To Run Python Script When Blender Starts

GOAL

To run Python script when Blender starts only once or every time.

Environment

Blender 2.83
Windows 10

Method

I created a simple Python script “Documents\blenderPython\test\spheres.py” to add spheres as below

import bpy
for i in range(3):
    bpy.ops.mesh.primitive_uv_sphere_add(radius=1, location=((i-1)*3, 0, 3))

Only once

Start Blender with command

Start blender in command prompt with an argument -P or –python.
Reference: Python Options in Blender 2.91 Manual

(more…)

How to show/hide header and sidebar in Blender

This is just a Tips.

GOAL

To hide/show headers and side bars in Blender.

Environment

Blender 2.83
Windows 10

How to hide headers

Right-mouse-click the header and check buttons off.

How to display header

Click dropdown button at the boundary of the editor.

You can show Sidebar in the same way.

How to hide sidebar

Method1. Use View menu and check click View > Sidebar off.

You can hide Toolbar, Sidebar, Toon Settings in the same way.

Method2. drag and drop the edge of sidebar to the right

Where is user preference file of Blender

GOAL

To find preference file of Blender and view the contents of the file.

Environment

Blender 2.83 (I’m using 2.83 because it is LTS)
Windows 10

What is saved in preference files?

There are two areas where Blender’s defaults are stored:

The Preferences file stores keymap, add-ons theme and other options.

The Startup File stores the scene, Workspaces and interface which is displayed at startup and when loading a new file (File ‣ New).

from Blender2.91 manual
(more…)