I created a cylinder via python.
I rotated it it 2 times (y and z axis). Then moved it up. Then i changed the origin to be in world center and rotated in on z - axis.
So the result is like this (which is ok)
then i added these line to my code
# expected: rotation "in place" - so same as before, but vertical
setOriginToGeometry(bpy.context.active_object)
bpy.ops.transform.rotate(value = 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)
and as i wrote in the comments i expected the green bar to rotate "just in place", instead i got this:
so obviously i am doing and understanding something wrong, but what? Any help appreciated!
my code:
import bpy
import math
def setOriginToCursor(object):
bpy.context.view_layer.objects.active = object
bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
def setOriginToGeometry(object):
bpy.context.view_layer.objects.active = object
bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN')
i = 0
name = "object"
halfPi = math.pi / 2
radius = 3
number_of_objects = 1
angle = 2 * math.pi / number_of_objects
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))
new_Name = name + '_' + str(i)
bpy.context.active_object.name = new_Name
# rotation 90 y-Axis, so i can see it from top view (result : horizontal)
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)
# rotation 90 on z axis, so it is vertical
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)
# move it up on y-axis
bpy.context.active_object.location[0] = math.sin(angle*i)*radius
bpy.context.active_object.location[1] = math.cos(angle*i)*radius
bpy.context.active_object.location[2] = 0
#i = 2
# works as expected
setOriginToCursor(bpy.context.active_object)
# moved and rotated to the left from origin - horizontal
bpy.ops.transform.rotate(value = 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)
# expected: rotation "in place" - so same as before, but vertical
# but it is: in world origin :(
setOriginToGeometry(bpy.context.active_object)
bpy.ops.transform.rotate(value = 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)