Removing rotation without affecting object

Hello, I am still working on an export-/import-script. What I try to figure out at the momen is the following…

If I load an .obj-file into Blender it might happen that it includes some rotation (the files I am using have often an rotation around the x-axis of 90°). What I would like to do is now to remove the rotation, i.e. set it to 0 instead of an Euler-value of 1.571. If I simply adjust the value stored in objects.rotation_euler.x the value turns to 0 but also my object is rotated.

I would like to keep the object as it is imported (with the 90° rotation on the x-axis) but would like to set the value to 0… somehow chaning the “alignment”. Do not know how I can explain that better, sorry.

Any clues for what I should look?

The easist way is probably to use the transform_apply operator:

ob = bpy.context.object
bpy.ops.object.transform_apply({‘selected_editable_objects’: [ob]}, rotation=True)

There’s also Mesh.transform(), but non-uniform scaling could distort your object (dunno how to do it properly)


Using transform_apply works like a charm… have to learn more about this kind of things. Appreciate your help.