0
$\begingroup$

I want to store the rotation of an object to be able to change it back after some operations. From my little coding experience "rot" should stay persistent and not be changed in the next line by "bpy.ops.object.transform_apply". Am I missing something?

import bpy

obj = bpy.context.object

rot = obj.rotation_euler
print("store object rotation", rot)
#evaluates correct

bpy.ops.object.transform_apply(location=False, rotation=True, scale=False)
print("rot after rotation-apply", rot)
#problem: rot has changed to (0, 0, 0)

#other operations

#problem: rotation cant be set back.
obj.rotation_euler = (rot)
print("gameobject_final_rotation: ",  obj.rotation_euler)
$\endgroup$
3
$\begingroup$

obj.rotation_euler is a reference to the rotation object which is affected by bpy.ops.object.transform_apply. In order to store the old rotation in a variable you can use:

rot = obj.rotation_euler.copy()
$\endgroup$
  • $\begingroup$ Thank you very much, looks like i realy have to improve my python knowledge :) $\endgroup$ – A M Aug 18 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.