import bpy, bmesh
from mathutils import Euler
import math
import mathutils
active = bpy.context.scene.objects['Suzanne']
obj = active.rotation_euler
for o_sel in bpy.context.selected_objects:
selected = o_sel.rotation_euler
for o in bpy.context.selected_objects:
if obj[-1] == selected[-1]:
print('same angle')
pass
else:
o.rotation_euler = (0, 0, obj[-1])
mesh = bpy.context.object.data
bpy.ops.object.editmode_toggle()
bm = bmesh.from_edit_mesh(mesh)
bmesh.ops.rotate(bm, verts=bm.verts, cent=(0.0, 0.0, 0.0), matrix=mathutils.Matrix.Rotation(-obj[-1], 4, 'Z'))
bmesh.update_edit_mesh(mesh)
bm.free()
bpy.ops.object.editmode_toggle()
In Blender 2.93, let's say that I have one active object and I want all the selected objects rotate only their origin to match the rotation of the active one. After couple of hours I have faced a roadblock, where I can get the rotation of the active object only and then loop through the selected ones leaving the active out from the loop, but after that I can't find the way for the selected ones to rotate their origins only.
UPDATE: I manage to make it work somehow, if I select on object and ru the script, it will work as it should be, but if I have more than one object selected it doesn't work. I have tried different loops combination without avail. The second issue is if I replace the scene object for any active one, even the active will rotate which is not right.
UPDATE 2: Here is a gif showing the script in action and the problem when selecting multiple objects. As you can see, the monkey has the axis angle that I want the other objects to have, when selecting the Torus and run the script it works, the same goes when I select the Cube, but if I select both, the script is not working properly.
In the second video if I have an active object the selected ones will not rotate.
mesh
is always that of the context object, IMO never useif float == float
test. (abs(float - float) < TOL
) It Requires objects to be in Euler rot mode, usingobj
for a rotation variable is somewhat confusing, ifrot = Euler()
thenrot.z
is z rotation. The bmesh rotation is only ever around Z axis. No need for edit mode. +1 for illustration lol. $\endgroup$