[Bf-extensions-cvs] [6b131222] master: Corrected "Change Bolt" removes linked duplicates
Robert Meerman
noreply at git.blender.org
Sun Feb 6 22:49:00 CET 2022
Commit: 6b131222ad251c4025e0506c3b8c96d1f8c5ef6c
Author: Robert Meerman
Date: Mon Feb 7 10:46:06 2022 +1300
Branches: master
https://developer.blender.org/rBA6b131222ad251c4025e0506c3b8c96d1f8c5ef6c
Corrected "Change Bolt" removes linked duplicates
Patch D10034
Prior to this patch, attempting to modify an existing bolt would
*replace* the object's mesh data block with a new one and remove the
original. This removal would essentially delete all linked duplicates.
Now the original mesh data block is modified in place, which avoids
having to copy anything between new and old object data blocks
(materials, names, etc), and causes all linked duplicates to reflect
the changes as users would expect.
===================================================================
M add_mesh_BoltFactory/Boltfactory.py
===================================================================
diff --git a/add_mesh_BoltFactory/Boltfactory.py b/add_mesh_BoltFactory/Boltfactory.py
index f2646704..58a7ae01 100644
--- a/add_mesh_BoltFactory/Boltfactory.py
+++ b/add_mesh_BoltFactory/Boltfactory.py
@@ -18,6 +18,7 @@
import bpy
+import bmesh
from mathutils import Matrix
from bpy.types import Operator
from bpy_extras.object_utils import AddObjectHelper
@@ -431,20 +432,21 @@ class add_mesh_bolt(Operator, AddObjectHelper):
(context.active_object.data is not None) and ('Bolt' in context.active_object.data.keys()) and \
(self.change == True):
obj = context.active_object
- oldmesh = obj.data
- oldmeshname = obj.data.name
mesh = createMesh.Create_New_Mesh(self, context)
- obj.data = mesh
+
+ # Modify existing mesh data object by replacing geometry (but leaving materials etc)
+ bm = bmesh.new()
+ bm.from_mesh(mesh)
+ bm.to_mesh(obj.data)
+ bm.free()
+
+ bpy.data.meshes.remove(mesh)
+
try:
bpy.ops.object.vertex_group_remove(all=True)
except:
pass
- for material in oldmesh.materials:
- obj.data.materials.append(material)
-
- bpy.data.meshes.remove(oldmesh)
- obj.data.name = oldmeshname
else:
mesh = createMesh.Create_New_Mesh(self, context)
obj = object_utils.object_data_add(context, mesh, operator=self)
More information about the Bf-extensions-cvs
mailing list