-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBSModifyPivotCreate.py
More file actions
56 lines (46 loc) · 1.91 KB
/
BSModifyPivotCreate.py
File metadata and controls
56 lines (46 loc) · 1.91 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
import bpy
import mathutils
objAxis = None
objTarget = None
checkParams = ["BSAxis_"]
def main(context):
if bpy.context.active_object != None:
if any(x in bpy.context.active_object.name for x in checkParams):
print("Active object cannot be a BSAxis Object")
else:
objTarget = bpy.context.active_object
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_pattern(pattern="BSAxis_*")
bpy.ops.object.delete()
objTarget.select_set(state=True)
bpy.ops.object.empty_add(type='ARROWS')
objAxis= bpy.context.active_object
objAxis.location = objTarget.location + objTarget.delta_location
objAxis.show_in_front = True
euRotationMX = objTarget.rotation_euler.to_matrix()
euRotationDeltaMX = objTarget.delta_rotation_euler.to_matrix()
RotationFullMX = euRotationMX @ euRotationDeltaMX
euRotationFull = RotationFullMX.to_euler()
objAxis.rotation_euler = euRotationFull
objAxis.name = "BSAxis_"+objTarget.name
bpy.ops.object.select_all(action='DESELECT')
objAxis.select_set(state=True)
#bpy.context.scene.objects.active = objAxis
#objAxis.select = True
"""
With this operator we create an axis object wich we will use to define the new object pivot
"""
class BSModifyPivot_OT_Create(bpy.types.Operator):
"""Create pivot for past modifications"""
bl_idname = "object.bsmodify_pivot_create"
bl_label = "BS Modify Object Pivot Create"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
main(context)
return {"FINISHED"}
def register():
bpy.utils.register_class(BSModifyPivot_OT_Create)
def unregister():
bpy.utils.unregister_class(BSModifyPivot_OT_Create)