How to get orientation of the local axis in python?

  • 1
    $\begingroup$ Isn't it the object orientation? Object.matrix_world $\endgroup$
    – CodeManX
    Aug 20, 2014 at 12:40

2 Answers 2


As Codemax answered. Thanks to him. Here is an example how i can rotate Localy an active object at Y-Axis.

activeObj = bpy.context.scene.objects.active
activeObjMatrix = activeObj.matrix_world
theAxis = (activeObjMatrix[0][1], activeObjMatrix[1][1], activeObjMatrix[2][1])
bpy.ops.transform.rotate(value=rotateValue, axis=theAxis)
  • $\begingroup$ You don't give any details on rotateValue. I take it that's an XYZ vector, like (1.5,3,.71) and in radians? $\endgroup$
    – Tango
    Feb 23, 2021 at 1:50
  • 1
    $\begingroup$ @Tango it's a float value, in radians. With a value of pi/2 you will rotate 90° around local Y axis. By the way for X local axis and Z local axis just replace the second index in each element of theAxis by 0 or 2 respectively $\endgroup$
    – Gorgious
    Mar 11, 2021 at 3:35
  • $\begingroup$ @Gorgious: Thank you! $\endgroup$
    – Tango
    Mar 11, 2021 at 5:07

You can use a simple theorem of linear algebra to do this:

'Every column of the (3 by 3)transformation matrix is the (unit) vector along rotated(transformed) axis'

You can use the following code to achieve the goal of this theorem:

Import bpy
From mathutils import Vector

obj = bpy.context.active_object
mat = obj.matrix_world
localX = Vector((mat[0][0],mat[1][0],mat[2][0]))
localY = Vector((mat[0][1],mat[1][1],mat[2][1]))
localZ = Vector((mat[0][2],mat[1][2],mat[2][2]))

You must log in to answer this question.

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