I’ve updated the Tidy script so it will switch to pose mode and actually move the bones instead of just assigning it to the collection. I’ve also made it more efficient(I hope). It is the rig_tidey_bone_layers4.0.py.
https://drive.google.com/drive/folders/1vVy5_HLU6bodWIKrSod6nbtKbnS4vRcf?usp=drive_link
For those who just want to see the code without having to download:
import bpy
# Get active object
rig = bpy.context.active_object
#Check to make sure it's an armature.
if rig and rig.type == "ARMATURE":
#Switch to pose mode
bpy.ops.object.mode_set(mode='POSE')
#Set array for Collection name and Bone name search
Type = ["DEF","MCH"]
#Loop thru Type. First is DEF then MCH.
for TName in Type:
if TName == "DEF":
Deform = True
else:
Deform = False
#Get collection
tcol = rig.data.collections.get(TName)
#If collection doesn't exist then create it
if not tcol:
tcol = rig.data.collections.new(TName)
#Add dash to the Type for searching.
TN = TName+"-"
#loop thru all bones
for bone in rig.pose.bones:
#Make sure bone isn't selected
bone.bone.select = False
#Check if bone name contains the search type. DEF- or MCH-
if bone.name.startswith(TN):
bone.bone.select = True
bone.bone.use_deform = Deform
bone.lock_location = [True, True, True]
bone.lock_scale = [True, True, True]
bone.lock_rotation = [True, True, True]
if bone.rotation_mode in ['AXIS_ANGLE','QUATERNION']:
bone.lock_rotation_w = True
#Moves all selected bones in pose mode to the collection.
bpy.ops.armature.move_to_collection(collection_index=tcol.index)