Tuesday, May 2, 2023

tip for querying geometry parented to armature

was working on a quadruped rig script which had lots of geometry meshes parented to the armature - but then i wanted a way to make the meshes unselectable so this is a small snippet that relates to that.  it has a little on looping over objects in blender scene (tested in Blender 2.79)

#tested in Blender 2.79
#simple snippet to query all geometry under armature
import bpy
armature = "putArmatureNameHere" #the data object name for armature
geometryUnderArmature = []
for obj in bpy.data.objects:
    if not obj.parent:
        continue
    if not obj.type == "MESH":
        continue
    if obj.parent.type == "ARMATURE" and obj.parent.name == armature:
        geometryUnderArmature.append(obj.name)
        
print(geometryUnderArmature)

#snippet to restrict viewport selection on given geometry
for geoName in geometryUnderArmature:
    bpy.data.objects[geoName].hide_select = True