2
$\begingroup$

I have created a grid of hexagons. I want to animate the rotation of a series of them diagonally, so I have parented each hexagon to its own Empty, and rotated the Empty's orientation to the angle I want to rotate the hexagons at. But when I try to rotate each Empty on its local x-axis using python script, I can't seem to get the expected rotation. What I've tried so far:

Selected Empty in 3D viewport, then ran (where the value "1.5708" is the equivalent of rotating 90 degrees):

bpy.context.object.rotation.euler[0] = 1.5708

or . . .

bpy.ops.transform.rotate(value=1.5708, 
                         axis=(0.866025, 0.5, 0), 
                         constraint_axis=(True, False, False), 
                         constraint_orientation='LOCAL', 
                         mirror=False,
                         proportional='DISABLED', 
                         proportional_edit_falloff='SMOOTH', 
                         proportional_size=1, 
                         release_confirm=True)

The first one results in an error:

Traceback (most recent call last):
File "", line 1, in
AttributeError: 'Object' object has no attribute 'rotation'

The second one rotates the Empty, but not according to local x-axis. (looks like maybe global x-axis)

Note: the above commands come from the info panel where first one is the same as setting rotation in the "Properties" panel (N key in 3D Viewport) and second one is the result of using the 3D Manipulation Widget

I am using Blender 2.73a on Mac OSX 10.8.5

$\endgroup$
1
  • $\begingroup$ The first one needs to be rotation_euler (underscore instead of . ) $\endgroup$ Feb 7, 2015 at 19:13

1 Answer 1

4
$\begingroup$

Your first attempt did not work because (as Ray Mairlot pointed out) the attribute is rotation_euler, not rotation.euler. Further more, with the proper notation it will only rotate the active object, not all objects selected.

This five line script rotates all selected objects by 90° on the local X axis.

import bpy
from math import pi
for ob in bpy.context.selected_objects:
    ob.rotation_euler[0] = pi/2
    ob.convert_space(from_space='LOCAL', to_space='WORLD')

The from math import pi line is just so we can use pi/2 instead of 1.5708 as the value to rotate by.

$\endgroup$

You must log in to answer this question.

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