-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalign_cursor_to_object.py
More file actions
69 lines (51 loc) · 2.05 KB
/
align_cursor_to_object.py
File metadata and controls
69 lines (51 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
Align Cursor to Object - Snaps the 3D cursor to the active object's transform.
In Object Mode, sets the cursor's location AND rotation to exactly match
the active object, making it a one-click inverse of "Align Object to Cursor".
Ideal for quickly setting up the cursor as a reference point before further
pivot or alignment operations.
"""
import bpy
from typing import Optional
def align_cursor_to_active(context) -> Optional[str]:
"""Set cursor location and rotation to match the active object.
Args:
context: Current Blender context
Returns:
Error message if the operation cannot proceed, None on success.
"""
active = context.active_object
if not active:
return "No active object"
cursor = context.scene.cursor
cursor.location = active.location.copy()
cursor.rotation_euler = active.rotation_euler.copy()
return None
class VIEW3D_OT_align_cursor_to_active(bpy.types.Operator):
"""Snap the 3D cursor to the active object's location and rotation"""
bl_idname = "view3d.align_cursor_to_active"
bl_label = "Cursor to Active Object"
bl_description = (
"Snap the 3D cursor to the active object's exact location and rotation. "
"One-click setup for further pivot or alignment operations"
)
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return context.mode == 'OBJECT' and context.active_object is not None
def execute(self, context):
error = align_cursor_to_active(context)
if error:
self.report({'ERROR'}, error)
return {'CANCELLED'}
return {'FINISHED'}
# ─── Registration ─────────────────────────────────────────────────────────────
classes = (
VIEW3D_OT_align_cursor_to_active,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)