Skip to content

Commit 076796e

Browse files
apply modifier to all same user
1 parent c29a427 commit 076796e

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

__init__.py

+34-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
if "bpy" in locals():
99
import importlib
1010
importlib.reload(apply_all)
11+
importlib.reload(apply_multi_user)
1112
else:
1213
from . import apply_all
14+
from . import apply_multi_user
1315

1416
import bpy
1517

@@ -56,6 +58,14 @@ def main_instance(self, context):
5658
context.scene.filename_path = "scene"
5759
name = "scene"
5860

61+
62+
63+
64+
# here we can apply modifier etc...
65+
66+
67+
68+
5969
fn = os.path.join(basedir, name) + "_gpu.glb"
6070

6171
wm = bpy.types.WindowManager
@@ -380,6 +390,27 @@ def execute(self, context):
380390
# raise the exception again
381391
raise e
382392

393+
class ApplyMultiUser(bpy.types.Operator):
394+
bl_idname = "object.apply_multi_user"
395+
bl_label = "Apply modifier to multi user"
396+
397+
def execute(self, context):
398+
try:
399+
self.report(
400+
{"INFO"}, "----- ----- ----- Sougen Scripts ----- ----- -----")
401+
self.report({"INFO"}, "Applied modifier to multi user")
402+
bpy.context.window.cursor_set("WAIT")
403+
# loading = True
404+
apply_multi_user.applyModifierToMultiUser(self, context)
405+
bpy.context.window.cursor_set("DEFAULT")
406+
# loading = False
407+
return {"FINISHED"}
408+
except Exception as e:
409+
print("Something went wrong")
410+
self.report({"ERROR"}, "Something went wrong")
411+
# raise the exception again
412+
raise e
413+
383414
class BakeCamera(bpy.types.Operator):
384415
bl_idname = "object.simple_operator"
385416
bl_label = "Camera Bake Export"
@@ -585,10 +616,12 @@ def draw(self, context):
585616
icon="MOD_BUILD", depress=loading)
586617
layout.operator("object.curves_export",
587618
icon="FORCE_CURVE", depress=loading)
619+
layout.operator("object.apply_multi_user",
620+
icon="EDITMODE_HLT", depress=loading)
588621

589622

590623
blender_classes = [BakeCamera, SimpleGLTF, GLTF_Collider,
591-
GLTF_PT_Panel, GLTF_Instance, Curves_Export]
624+
GLTF_PT_Panel, GLTF_Instance, Curves_Export, ApplyMultiUser]
592625

593626

594627
def register():

__pycache__/__init__.cpython-39.pyc

746 Bytes
Binary file not shown.
995 Bytes
Binary file not shown.

apply_multi_user.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import bpy
2+
3+
def applyModifierToMultiUser(self, context):
4+
active = bpy.context.selected_objects[0]
5+
6+
if (active == None):
7+
print("Select an object")
8+
return
9+
if (active.type != "MESH"):
10+
print("Select an mesh object")
11+
return
12+
13+
14+
mesh = active.to_mesh(preserve_all_data_layers=False, depsgraph=None)
15+
16+
linked = []
17+
selected = []
18+
19+
print(mesh)
20+
21+
for obj in bpy.data.objects:
22+
if obj.data == active.data:
23+
linked.append(obj)
24+
25+
26+
bpy.ops.object.make_single_user(object=True, obdata=True, material=False, animation=False, obdata_animation=False)
27+
bpy.ops.object.modifier_apply(modifier="Decimate")
28+
29+
30+
for obj in linked:
31+
obj.select_set(state=True)
32+
obj.modifiers.clear()
33+
34+
35+
bpy.ops.object.make_links_data(type='OBDATA')
36+

0 commit comments

Comments
 (0)