3
$\begingroup$

How do I rotate an object around the local axis using python?

Maybe something like this answer.

$\endgroup$

2 Answers 2

4
$\begingroup$

I found this question

and from it I got this:

import bpy
import numpy
from mathutils import Euler

def set_loc_rotation(obj, value):
    rot = Euler(value, 'ZYX')
    obj.rotation_euler = (obj.rotation_euler.to_matrix() @ rot.to_matrix()).to_euler(obj.rotation_mode)
    
obj=bpy.data.objects['Cube'];

set_loc_rotation(obj, numpy.radians([30,0,0])) #rotates by 30 deg on local x axis
set_loc_rotation(obj, numpy.radians([0,0,30])) #rotates by 30 deg on local z axis
$\endgroup$
2
  • $\begingroup$ How about doing this in a keyframing? $\endgroup$ Commented Jun 1, 2024 at 18:17
  • $\begingroup$ why do you use rotation mode 'ZYX'? $\endgroup$ Commented Jun 14, 2024 at 3:15
-1
$\begingroup$

is that what you are looking for?

bpy.data.objects['Cube'].rotation_euler[0] = 1.5 # x
$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.