Changeset View
Changeset View
Standalone View
Standalone View
add_mesh_BoltFactory/Boltfactory.py
| Context not available. | |||||
| import bpy | import bpy | ||||
| import bmesh | |||||
| from mathutils import Matrix | from mathutils import Matrix | ||||
| from bpy.types import Operator | from bpy.types import Operator | ||||
| from bpy_extras.object_utils import AddObjectHelper | from bpy_extras.object_utils import AddObjectHelper | ||||
| Context not available. | |||||
| (context.active_object.data is not None) and ('Bolt' in context.active_object.data.keys()) and \ | (context.active_object.data is not None) and ('Bolt' in context.active_object.data.keys()) and \ | ||||
| (self.change == True): | (self.change == True): | ||||
| obj = context.active_object | obj = context.active_object | ||||
| oldmesh = obj.data | |||||
| oldmeshname = obj.data.name | |||||
| mesh = createMesh.Create_New_Mesh(self, context) | 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: | try: | ||||
| bpy.ops.object.vertex_group_remove(all=True) | bpy.ops.object.vertex_group_remove(all=True) | ||||
| except: | except: | ||||
| pass | pass | ||||
| for material in oldmesh.materials: | |||||
| obj.data.materials.append(material) | |||||
| bpy.data.meshes.remove(oldmesh) | |||||
| obj.data.name = oldmeshname | |||||
| else: | else: | ||||
| mesh = createMesh.Create_New_Mesh(self, context) | mesh = createMesh.Create_New_Mesh(self, context) | ||||
| obj = object_utils.object_data_add(context, mesh, operator=self) | obj = object_utils.object_data_add(context, mesh, operator=self) | ||||
| Context not available. | |||||