I have this python script which perfectly distributes my cylinders on a circle.
def create_circular_array(number_of_objects, radius, name):
# angle = radian / numbers_of_ob
angle = 2 * math.pi / number_of_objects
halfPi = math.pi / 2
# loop number_of_ob
for i in range(number_of_objects):
new_Name = name + '_' + str(i)
bpy.ops.mesh.primitive_cylinder_add(radius=1, depth=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(0.1, 0.1, 1))
# bpy.context.active_object.name = new_Name
bpy.ops.transform.rotate(value = halfPi, orient_axis='Y', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, True, False), mirror=True, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
bpy.ops.transform.rotate(value = math.pi * 2 - angle * i + math.pi / 2, orient_axis='Z', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, False, True), mirror=True, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
bpy.data.objects[i].location[0] = math.sin(angle*i)*radius # x = sine(angle*i)*radius
bpy.data.objects[i].location[1] = math.cos(angle*i)*radius # y = cosine(angle*i)*radius
bpy.data.objects[i].location[2] = 0
create_circular_array(16, 2, 'inner')
But...
If I uncomment this line
# bpy.context.active_object.name = new_Name
Everything is messed up. The coordinates and angles are wrong.
What am I doing wrong here!?
and yes, i want to rename my newly created objects. So it is not a solution for me to delete or comment out that line.