Keymap via Python

It’s too risky to manually customize your keys via the editor. I did that in the past and a newer version broke it. This time I’m doing it via scripting which is much easier and more readable! The way to go about this is create two functions, and then set/disable as many as you like. Once you’re satisfied with your customization, you put the *.py file into the scripts/startup folder.

Script: Crease Removal

This is a well known crease technique. With Blender, select a string of edges that you want to turn it into a crease, and do a Alt+V, position it, and then do a Loop Cut (Ctrl+R) in the center. Push it inward and you have a nice crease effect.

Recently I tried to reverse this via Python scripting in Blender. I knew what needed to be done but failed in my first attempt because the indices of edges get randomized after you deleted or removed any of them. It was chasing after the wind, so I thought of another way to go about it and today it finally dawned on me. This is my way of brute-forcing it, and it works, even on multiple creases at once.

This script only works effectively on a crease pattern. This can be turned into an addon and bind it to a hotkey easily. Let’s see if this can be appended to the delete menu.

Blender’s automation with Python

When I first got my own computer back in the late 90s, programming was one of the things I explored. BASIC, Pascal, Assembly etc… but I didn’t get very far with it. There was no YouTube that teach you programming at the time, and I was on my own with books at a young age. On top of this, my mind is wired for visual art and I pick things up in art a lot quicker than in programming.

Now here in 2020, there are tons of tutorials and courses on programming! What a fun time to explore programming if you’re just starting out. As for me, my passion is in visual art. The little knowledge that I have with coding are only used for automating tasks, which is the topic of this post.

Those on Windows have AutoHotkey, a free and open-source scripting language that allows users to easily create small to complex scripts for all kinds of tasks. For those on macOS and Linux, they’re out of luck because there isn’t a software like AutoHotkey for them (to my knowledge).

For Blender Artists, we have Python, built-in. I do a lot of things via shortcuts, and I have many times remapped keys for Krita and Blender. Last year when I installed a new version of Krita, it broke my keymap. The same happened with Blender. Recently I learned that if you’re going to make changes to Blender’s keymap, keep it to the minimum otherwise there’s a chance of it breaking in future version(s). They recommend Scripting and that got me looking into it.

I’m the kind of person that like my keys to be smart. I want to accomplish more tasks with less keys, which is not possible with Blender without Scripting. To give an example: The “J” in Blender is for “Connect Vertex Path.” I want the “J” to accomplish more than one tasks depending on the context. If two or more objects are selected, I want the “J” to combine (join) them into one object. If two or more vertices are selected, I want “J” to “Connect Vertex Path” but if two or more edges or faces, I want “J” to “Subdivide.” But if I’m in Sculpt mode, I want “J” to pick a “Snake Hook” brush (for example).

This setup is very powerful, and it’s how key customization should be done!