I am running the following code. I would like to rotate the selected blocks about the x-axis in the center. However, it is rotating about the corner. Can I ask for assistance?
import bpy
from mathutils import Matrix, Vector
import math
angle = math.radians(45)
for obj in bpy.data.objects:
if(obj.location.x > 1.1):
obj.select_set(True)
print(obj.location.x)
bpy.context.view_layer.objects.active = obj
bpy.ops.transform.rotate(value=math.radians(90) , orient_axis='X')
print("hello33")
I am running the following code. I would like to rotate the selected blocks about the x-axis in the center. However, it is rotating about the corner. Can I ask for assistance?
import bpy
from mathutils import Matrix, Vector
import math
angle = math.radians(45)
for obj in bpy.data.objects:
if(obj.location.x > 1.1):
obj.select_set(True)
print(obj.location.x)
bpy.context.view_layer.objects.active = obj
bpy.ops.transform.rotate(value=math.radians(90) , orient_axis='X')
print("hello33")
Share
Improve this question
asked Mar 6 at 3:46
ffejrekaburbffejrekaburb
7312 gold badges13 silver badges36 bronze badges
2
- there is similar portal Blender Stack Exchange -- I don't know but maybe it will be better for you. – furas Commented Mar 6 at 8:27
- reddit also has forum: Python: Rotate multiple objects around Bounding Box Center? : r/blender – furas Commented Mar 6 at 8:30
1 Answer
Reset to default 1I just played around a bit and came up with this:
import bpy
from mathutils import Matrix, Vector
import math
angle = math.radians(45)
# store old pivot setting
old_pivot = bpy.context.scene.tool_settings.transform_pivot_point
# set pivot point to bounding box
bpy.context.scene.tool_settings.transform_pivot_point = "BOUNDING_BOX_CENTER"
# --> https://docs.blender./api/current/bpy.types.ToolSettings.html#bpy.types.ToolSettings.transform_pivot_point
for obj in bpy.data.objects:
if(obj.location.x > 1.1):
obj.select_set(True)
print(obj.location.x)
bpy.context.view_layer.objects.active = obj
bpy.ops.transform.rotate(value=math.radians(45), orient_axis='X')
# restore old pivot setting
bpy.context.scene.tool_settings.transform_pivot_point = old_pivot
I only added the three lines. One to store the current setting of the pivot point, 2nd set the pivot point to "bounding box" and restore the old setting.
Also, I changed the angle to 45° so I can actually see the changes ;) Hope this works for you too. I tested with Blender 4.3.0.