Blender baking animation but clear not all constrains?
I just want to bake the child of constrain and want to keep the other becuse i need them for the weapon snap. I let ChatGPT generate a simple code to bake animation and clear constrains with the name of “Bake” but the code not works flawless. It seems the code just delete the child of from the activ bone instead of baking it. Sadly ChatGPT seems not be able to fix this, i ask here if somebody know how to make this code works like i wish?
2024-10-14 14-30-20.mp4import bpy
# Zeitrahmen für die Animation
start_frame = bpy.context.scene.frame_start
end_frame = bpy.context.scene.frame_end
# Sicherstellen, dass das aktive Objekt ein Armature ist
obj = bpy.context.active_object
if obj and obj.type == 'ARMATURE':
# Alle ausgewählten Bones durchgehen
selected_bones = bpy.context.selected_pose_bones
if selected_bones:
for bone in selected_bones:
# Suchen nach dem Constraint mit dem Namen "Bake"
for constraint in bone.constraints:
if constraint.name == "Bake":
# Den "Bake" Constraint muten, bevor die Animation gebaked wird
constraint.mute = True
print(f"Constraint 'Bake' für Bone '{bone.name}' deaktiviert.")
# Bake Animation nur für den aktiven Bone
bpy.ops.nla.bake(
frame_start=start_frame,
frame_end=end_frame,
only_selected=True, # Nur ausgewählte Bones
visual_keying=True, # Sichtbare Bewegungen baken
clear_constraints=False, # Andere Constraints behalten
use_current_action=True # Verwende aktuelle Aktion
)
# Lösche den "Bake" Constraint nach dem Backen
bone.constraints.remove(constraint)
print(f"Constraint 'Bake' für Bone '{bone.name}' gelöscht.")
else:
print("Keine Bones ausgewählt.")
else:
print("Kein Armature-Objekt ausgewählt.")