from .utils import showMessage
from .blender_objects import linkMeshData
import bpy




class NEEDLE_OT_LinkMeshes(bpy.types.Operator):
    bl_idname = "needle.link_meshes"
    bl_label = "Link all selected meshes"
    bl_options = {'REGISTER'}
    def execute(self, context):
        selected_objects = bpy.context.selected_objects
        if linkMeshData(selected_objects):
            showMessage("Linked " + str(len(selected_objects)) + " meshes", "Link Meshes")
        else:
            showMessage("Failed to link meshes", "Link Meshes")
        return {'FINISHED'}
