How to perform transforms using the current gizmo settings


I’m making an addon that aims basically to provide shortcuts to perform some simple actions with the transform Gizmos, ideally in any editor having transform gizmos.

So far I managed to make shortcuts to increase/decrease the gizmo size on the fly, now I’m on the next step: make translation/rotation using the keyboard arrows and page up/down keys.

And as you can see on my GitHub, I managed to do just that (well, for the transform only but the rest seems straightforward to do) using this:

bpy.ops.transform.translate(value=(0,1,0), orient_type='LOCAL')

But Ideally, I’d like to be able to let the user choose the kind of transform to perform and the orientation, and all this using as few shortcuts as possible.

TL;DR: I'd like to pick up the gizmo's settings instead of coding each case.

Currently I’m already using ⎇ Alt + to make local axes translations, as well as to manage the gizmo size. I could keep coding each case scenario and assign more hotkeys, but it sounds messy and too heavy on the keyboard.
I could add some UI in the sidebar to give the user some tools to set what he wants to do with the shortcuts, but that’s putting more weight on the user shoulders and there’s already something doing just that: the Gizmo!

Since the user already plays with the gizmo settings in order to set it to translate/rotate/scale and set the orientation, I hopped there could be a way to basically perform a transform based on the gizmo instead of coding each possible transform times each possible orientation.

Aka, replace the current
do a translation of 1 on the local X axis
by something like:
use the current transform gizmo and its orientation to add 1 value to the X axis

I saw bpy.ops.transform.from_gizmo(), but the manual doesn’t say much about it and it doesn’t recognize the “value” keyword so I’m not sure I can guess how to use it.

Also, not exactly related to this issue, but it seems that the Y and Z axis are inverted when rotating bones in pose mode. Any idea how to hide that in a simple manner off the user side?

Thanks for any help!

This is not true, bones’ axes are always the same, Y axis runs from head to tail, X axis is normal to Y and Z is normal to both the others, Bone roll will affect the orientations with regard to Global Axes of X and Z bone axes. This does not stop you rotating a bone in either its own Local Axes, or about a Global axis.

So anything you do needs to be able to specify whether you are rotating a bone’s Local axis, in either Euler, or Quaternion mode, or whether you want to rotate it about a Global axis, in which case using its current rotation matrix and manipulating that by a Global rotation matrix is probably the best way to go.

As for the other part of your question, using the transform matrix and manipulating parts of that is probably what you would want to do, so if you captured keystrokes x15 the object in question should increase its rotation by 15 degrees, this is easy to do if you decompose the object’s transform matrix and added something to whichever axis you wanted to alter. You should also investigate object world matrix to take into account any transforms due to parenting of an object to another that has transforms in operation.

Cheers, Clock.

1 Like

I’m back.

got it working \o/

1 Like