# This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import bpy bl_info = { "name": "Vertex_Transfer_Addon", "author": "Nick Alberelli", "description": "", "blender": (3, 6, 0), "version": (0, 0, 1), "location": "", "warning": "", "category": "Generic", } class TEST_OT_vertex_transfer(bpy.types.Operator): bl_idname = "test.vertex_transfer" bl_label = "Test Vertex Transfer" bl_description = ( "Transfer Active Vertex Group from Active object to Selected Objects" ) def invoke(self, context: bpy.types.Context, event: bpy.types.Event): return context.window_manager.invoke_props_dialog(self, width=400) def draw(self, context: bpy.types.Context): layout = self.layout scene = context.scene layout.prop(scene, "source_obj") layout.prop(scene, "target_obj") def transfer_vertex_group( self, context, vertex_group_name: str, target_obj: bpy.types.Object, source_obj: bpy.types.Object, ): source_obj.vertex_groups.active = source_obj.vertex_groups.get( vertex_group_name ) override = context.copy() override["selected_editable_objects"] = [target_obj, source_obj] override["active_object"] = source_obj override["object"] = source_obj # Appears to be required in this context with context.temp_override(**override): bpy.ops.object.data_transfer( data_type="VGROUP_WEIGHTS", use_create=True, vert_mapping='POLYINTERP_NEAREST', layers_select_src="ACTIVE", layers_select_dst="NAME", mix_mode="REPLACE", ) def execute(self, context: bpy.types.Context): source_obj = context.scene.source_obj target_obj = context.scene.target_obj for vertex_group in source_obj.vertex_groups: self.transfer_vertex_group( context, vertex_group.name, target_obj, source_obj ) return {'FINISHED'} class TEST_PT_vertex_transfer(bpy.types.Panel): bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = 'Test Vertex Transfer' bl_label = "Test Vertex Transfer" def draw(self, context: bpy.types.Context) -> None: self.layout.operator("test.vertex_transfer") def register(): bpy.utils.register_class(TEST_OT_vertex_transfer) bpy.utils.register_class(TEST_PT_vertex_transfer) bpy.types.Scene.source_obj = bpy.props.PointerProperty( name="source obj", type=bpy.types.Object ) bpy.types.Scene.target_obj = bpy.props.PointerProperty( name="target obj", type=bpy.types.Object ) def unregister(): bpy.utils.unregister_class(TEST_OT_vertex_transfer) bpy.utils.unregister_class(TEST_PT_vertex_transfer) del bpy.types.Scene.source_obj del bpy.types.Scene.target_obj