How to set transform orientation in code

In the 3d view:
On the bottom panel, on the right of the transform manipulator icon: Can change to: VIEW, NORMAL, GIMBAL, LOCAL, GLOBAL

How to do this in code though? According to the manual, it has to be done like this:
bpy.types.SpaceView3D.transform_orientation = ‘LOCAL’
But it has no effect.

What is the proper way to do this?

Same for
bpy.types.SpaceView3D.use_pivot_point_align = False
It has no effect

I figured it out. It should be:

context.space_data.use_pivot_point_align = False
context.space_data.transform_orientation = ‘LOCAL’

I also want to know about transform orientations via python. But the lines you wrote don’t work. Specifically, i would access the degrees of the transform orientations. It could be useful if you can manipoulate the from some text box or similar, or have a better list of the actual transfomr orientations.
If someone founded something useful could say here? thankyou!

Really strange discoverings. With this code you can create a new transform orientation, and you can assign really strange values to its matrix. For example you can create a shorter Z axis, or orientation with inverted axis.

import bpy

bpy.ops.transform.create_orientation(name = “Personal2”, overwrite = True)

bpy.context.scene.orientations[-1].matrix = (((1.0, 0.0, 0.0),
(0.0, -1.0, 0.0),
(0.0, 0.0, -0.5)))

How can i get the current orientation?
If I remember exactly, there was an add-on that does something with the transform orientations. Does anybody remember it?

I would like to create an orientation manager like this, but I need some help

The things I need are to get the current custom orientation (if it there is) and to convert a 3x3 matrix in 3 degree values for x y and z, and viceversa.

Hope you can help me. I really need a thing like this in architectural modeling.

Any knowledge about this topic please?

Thankyou! This is what i needed!

I found this, about the current orientation.
But if i write it in the code it says that SpaceView3D has no current_orientation attribute. What is the problem?

I write


what’s wrong?

Hi Lell,

You are looking at the class with, whereas you want to change the instance of that class
Eg context.space_data or loop thru the spaces of context.area etc

Below is some code that loops thru the current screen and shows each area and then each space and if it’s a 3d view the current_orientation

import bpy

def show_screen():
    #f = repr  #uncomment and use repr to show repr of instance
    f = type  #uncomment and use type to show the type
    context = bpy.context
    print("Screen: %s" %
    for area_index, area in context.screen.areas.items():
        print("	[%s] Area[%d] %s" % (area.type, area_index, f(area)))
        #print(" %s" % repr(
        for space_index, space in area.spaces.items():
            print("		[%s] space[%d] %s" % (space.type, space_index, f(space)))
            if space.type == 'VIEW_3D':
                print("		 current_orientation = %s" % repr(space.current_orientation))
       ["showscreen"] = show_screen

Output to console showing class names

>>> SS =['showscreen']
>>> SS()
Screen: Scripting
    [INFO] Area[0] <class 'bpy.types.Area'>
        [INFO] space[0] <class 'bpy.types.SpaceInfo'>
    [OUTLINER] Area[1] <class 'bpy.types.Area'>
        [OUTLINER] space[0] <class 'bpy.types.SpaceOutliner'>
        [PROPERTIES] space[1] <class 'bpy.types.SpaceProperties'>
    [VIEW_3D] Area[2] <class 'bpy.types.Area'>
        [VIEW_3D] space[0] <class 'bpy.types.SpaceView3D'>
         current_orientation = None
        [CONSOLE] space[1] <class 'bpy.types.SpaceConsole'>
    [PROPERTIES] Area[3] <class 'bpy.types.Area'>
        [PROPERTIES] space[0] <class 'bpy.types.SpaceProperties'>
        [VIEW_3D] space[1] <class 'bpy.types.SpaceView3D'>
         current_orientation = None
        [OUTLINER] space[2] <class 'bpy.types.SpaceOutliner'>
    [TEXT_EDITOR] Area[4] <class 'bpy.types.Area'>
        [TEXT_EDITOR] space[0] <class 'bpy.types.SpaceTextEditor'>
        [VIEW_3D] space[1] <class 'bpy.types.SpaceView3D'>
         current_orientation = None
    [CONSOLE] Area[5] <class 'bpy.types.Area'>
        [CONSOLE] space[0] <class 'bpy.types.SpaceConsole'>


Output to console showing repr of instance names

Screen: Scripting
    [INFO] Area[0]['Scripting']...Area
        [INFO] space[0]['Scripting']...SpaceInfo
    [OUTLINER] Area[1]['Scripting']...Area
        [OUTLINER] space[0]['Scripting']...SpaceOutliner
        [PROPERTIES] space[1]['Scripting']...SpaceProperties
    [VIEW_3D] Area[2]['Scripting']...Area
        [VIEW_3D] space[0]['Scripting']...SpaceView3D
         current_orientation = None
        [CONSOLE] space[1]['Scripting']...SpaceConsole
    [PROPERTIES] Area[3]['Scripting']...Area
        [PROPERTIES] space[0]['Scripting']...SpaceProperties
        [VIEW_3D] space[1]['Scripting']...SpaceView3D
         current_orientation = None
        [OUTLINER] space[2]['Scripting']...SpaceOutliner
    [TEXT_EDITOR] Area[4]['Scripting']...Area
        [TEXT_EDITOR] space[0]['Scripting']...SpaceTextEditor
        [VIEW_3D] space[1]['Scripting']...SpaceView3D
         current_orientation = None
    [CONSOLE] Area[5]['Scripting']...Area
        [CONSOLE] space[0]['Scripting']...SpaceConsole

Thankyou for explanation! That seems logical!

anyone know the 2.8 code ? could’nt find out this one is tricky


bpy.context.scene.transform_orientation_slots = ‘LOCAL’

not working


not being recognize, altho its on the 2.8 api page

if we set orientation not with the header but with the set tranfrom orientation operator we can get this code in the info panel


not working either, how strange

that massive upvote tho

transform_orientation_slots is an array, so:

bpy.context.scene.transform_orientation_slots[0].type = ‘LOCAL’

I’m not sure what the purpose of slots other than 0 are, but 0 seems to be the viewport.

Edit: 1 seems to be the transform gizmo orientation.


How strange, how did you knew that it was an array ?

I can’t remember how I figured it out. I came across it a while back. I think maybe I just noticed it was plural, and gave it a try.

1 Like

by the way do you know how to invoke the whole list of orientation types ?


this is the string, i want to print the whole list and not just the stringle letters
can’t get my hands on it, i thinks is related to the data branch, not sure

I didn’t know, but I was curious and did a bit of searching and found this:

Just swap out the second to last line in the solution with:
enum = enum_members_from_instance(bpy.context.scene.transform_orientation_slots[0], "type")