What Python command rotates an object around the 3D Cursor?
Asked
Active
Viewed 4,571 times
1 Answers
7
Assume you already have the Pivot Point set to 3D Cursor (although this could be done in Python also)

You can use the operator bpy.ops.transform.rotate(), but you need to override the context or else it will only rotate around the object's median point.
import bpy
def get_override(area_type, region_type):
for area in bpy.context.screen.areas:
if area.type == area_type:
for region in area.regions:
if region.type == region_type:
override = {'area': area, 'region': region}
return override
#error message if the area or region wasn't found
raise RuntimeError("Wasn't able to find", region_type," in area ", area_type,
"\n Make sure it's open while executing script.")
#we need to override the context of our operator
override = get_override( 'VIEW_3D', 'WINDOW' )
#rotate about the X-axis by 45 degrees
bpy.ops.transform.rotate(override, value=6.283/8, axis=(1,0,0))
Garrett
- 6,596
- 6
- 47
- 75