diff options
author | Robert Meerman <meermanr> | 2022-02-07 00:46:06 +0300 |
---|---|---|
committer | Aaron Keith <aaroninusa@gmail.com> | 2022-02-07 00:48:28 +0300 |
commit | 6b131222ad251c4025e0506c3b8c96d1f8c5ef6c (patch) | |
tree | 472847a6bfe1eb494497466c88f0afeb1c0a4f80 /add_mesh_BoltFactory | |
parent | 6da09c309d756cecac66ac27257414c36f9b51b7 (diff) |
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.
Diffstat (limited to 'add_mesh_BoltFactory')
-rw-r--r-- | add_mesh_BoltFactory/Boltfactory.py | 18 |
1 files changed, 10 insertions, 8 deletions
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) |