-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathops.py
More file actions
111 lines (79 loc) · 3.05 KB
/
Copy pathops.py
File metadata and controls
111 lines (79 loc) · 3.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import bpy
from bpy.types import Operator
from bpy.utils import register_class, unregister_class
from .utils.binder import bind_update, get_binded_objects
from .utils.drivers import remove_driver
class OSB_OT_bind(Operator):
"""Binds the selected meshes to the active one"""
@classmethod
def poll(cls, context):
if len(bpy.context.selected_objects) <= 1:
cls.poll_message_set("Select more than one object.")
return False
return True
bl_idname = "osb.bind"
bl_label = "Bind Selected to Active"
bl_description = "Binds the selected meshes to the active one"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
active_mesh = bpy.context.object
selected_meshes = bpy.context.selected_objects
for object in selected_meshes:
if object.type != "MESH":
continue
if not object.data:
continue
if object == active_mesh:
continue
object.data["sp_binded_object"] = active_mesh
bind_update(self, context)
self.report({"INFO"}, "Objects binded!")
return {"FINISHED"}
class OSB_OT_unbind(Operator):
"""Unbinds the selected meshes"""
bl_idname = "osb.unbind"
bl_label = "Unbind Selected Objects"
bl_description = "Unbinds the selected meshes"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
selected_meshes = bpy.context.selected_objects
for object in selected_meshes:
if not object.data:
continue
if not object.data.get("sp_binded_object"):
continue
del object.data["sp_binded_object"]
# Clears shapekey drivers
target_shape_keys = object.data.shape_keys
for target_key in target_shape_keys.key_blocks:
remove_driver(target_key, target_shape_keys, "value") # type: ignore
return {"FINISHED"}
class OSB_OT_purge(Operator):
"""Purges all binded objects"""
bl_idname = "osb.purge"
bl_label = "Purge All Binded Objects"
bl_description = "Unbinds all binded objects"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
binded_objects = get_binded_objects()
for object in binded_objects:
if not object.data:
continue
if not object.data.get("sp_binded_object"):
continue
del object.data["sp_binded_object"]
if object.type != "MESH":
continue
# Clears shapekey drivers
target_shape_keys = object.data.shape_keys
for target_key in target_shape_keys.key_blocks:
remove_driver(target_shape_keys, target_key, "value") # type: ignore
return {"FINISHED"}
def register_ops():
register_class(OSB_OT_bind)
register_class(OSB_OT_unbind)
register_class(OSB_OT_purge)
def unregister_ops():
unregister_class(OSB_OT_bind)
unregister_class(OSB_OT_unbind)
unregister_class(OSB_OT_purge)