Basic Start of Armature Selection

This commit is contained in:
Yusarina
2024-07-22 23:13:10 +01:00
parent f0323577c9
commit 06c7cff4b7
9 changed files with 86 additions and 74 deletions
+9 -9
View File
@@ -2,7 +2,7 @@ import bpy
from typing import List, Optional
from bpy.types import Operator, Context, Object
from ..core.register import register_wrap
from ..core.common import fix_uv_coordinates
from ..core.common import fix_uv_coordinates, get_selected_armature
from ..functions.translations import t
@register_wrap
@@ -14,21 +14,22 @@ class JoinAllMeshes(Operator):
@classmethod
def poll(cls, context: Context) -> bool:
return context.mode == 'OBJECT'
return context.mode == 'OBJECT' and get_selected_armature(context) is not None
def execute(self, context: Context) -> set:
self.join_all_meshes(context)
return {'FINISHED'}
def join_all_meshes(self, context: Context) -> None:
if not bpy.data.objects:
self.report({'INFO'}, "No objects in the scene")
armature = get_selected_armature(context)
if not armature:
self.report({'WARNING'}, "No armature selected")
return
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
meshes: List[Object] = [obj for obj in bpy.data.objects if obj.type == 'MESH']
meshes: List[Object] = [obj for obj in bpy.data.objects if obj.type == 'MESH' and 'Armature' in obj.modifiers and obj.modifiers['Armature'].object == armature]
for mesh in meshes:
mesh.select_set(True)
@@ -52,7 +53,7 @@ class JoinSelectedMeshes(Operator):
@classmethod
def poll(cls, context: Context) -> bool:
return context.mode == 'OBJECT'
return context.mode == 'OBJECT' and len([obj for obj in context.selected_objects if obj.type == 'MESH']) > 1
def execute(self, context: Context) -> set:
self.join_selected_meshes(context)
@@ -61,8 +62,8 @@ class JoinSelectedMeshes(Operator):
def join_selected_meshes(self, context: Context) -> None:
selected_objects: List[Object] = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']
if not selected_objects:
self.report({'WARNING'}, "No mesh objects selected")
if len(selected_objects) < 2:
self.report({'WARNING'}, "Please select at least two mesh objects")
return
bpy.ops.object.mode_set(mode='OBJECT')
@@ -81,4 +82,3 @@ class JoinSelectedMeshes(Operator):
self.report({'INFO'}, "Selected meshes joined successfully")
else:
self.report({'WARNING'}, "No mesh objects selected")