0
$\begingroup$

I'd like to create a text object that displays the rotation angle, in degrees, of an object.

I found this code snippet which does almost exactly what I want, except gives units in radians.

I'm a noob when it comes to Python & Blender. Can someone show me how to make this read in degrees? I assume there is a convert function, but i have no idea how to integrate one.

Thanks in advance.

import bpy

scene = bpy.context.scene
obj = scene.objects['Text']

def recalculate_text(scene):
    obj.data.body = f'{bpy.data.objects["Cylinder.003"].rotation_euler[0]}'

bpy.app.handlers.frame_change_pre.append(recalculate_text)
```
$\endgroup$
1
  • $\begingroup$ degree = radian*(180/pi) $\endgroup$
    – james_t
    Commented Apr 1, 2023 at 15:22

1 Answer 1

1
$\begingroup$
from math import degrees

def recalculate_text(scene): # fail when rotation_mode in {QUATERNION, AXIS_ANGLE}
    obj.data.body = f'{degrees(bpy.data.objects["Cylinder.003"].rotation_euler[0])}'

or

def recalculate_text(scene): # fail when rotation_mode in {QUATERNION, AXIS_ANGLE}
    obj.data.body = f'{bpy.data.objects["Cylinder.003"].rotation_euler[0] * 57.29577951308232}'
$\endgroup$
1
  • $\begingroup$ That's great, thanks alot. FYI for anyone reading this in the future, the first snippet has "degrees" spleed as "degress". Otherwise perfect. $\endgroup$
    – Craig
    Commented Oct 6, 2022 at 0:32

You must log in to answer this question.

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