Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # THIS SCRIPT WAS GENERATED BY CHATGPT
- #
- import bpy
- # Mapping for IK to FK
- ik_to_fk_map = {
- "FK_Arm_1_L": "IK-TO-FK-SNAP_ARM_1_L",
- "FK_Arm_2_L": "IK-TO-FK-SNAP_ARM_2_L",
- "FK_Wrist_L": "IK-TO-FK-SNAP_WRIST_L",
- "FK_Leg_1_L": "IK-TO-FK-SNAP_LEG_1_L",
- "FK_Leg_2_L": "IK-TO-FK-SNAP_LEG_2_L",
- "FK_Ankle_L": "IK-TO-FK-SNAP_ANKLE_L",
- "FK_Arm_1_R": "IK-TO-FK-SNAP_ARM_1_R",
- "FK_Arm_2_R": "IK-TO-FK-SNAP_ARM_2_R",
- "FK_Wrist_R": "IK-TO-FK-SNAP_WRIST_R",
- "FK_Leg_1_R": "IK-TO-FK-SNAP_LEG_1_R",
- "FK_Leg_2_R": "IK-TO-FK-SNAP_LEG_2_R",
- "FK_Ankle_R": "IK-TO-FK-SNAP_ANKLE_R",
- }
- # Mapping for FK to IK
- fk_to_ik_map = {
- "Wrist_IK_L": "FK-TO-IK-SNAP_WRIST_IK_L",
- "POLE_Elbow_L": "FK-TO-IK-SNAP_POLE_ELBOW_L",
- "CTRL_FOOT_L": "FK-TO-IK-SNAP_CTRL_FOOT_L",
- "POLE_Knee_L": "FK-TO-IK-SNAP_POLE_KNEE_L",
- "Wrist_IK_R": "FK-TO-IK-SNAP_WRIST_IK_R",
- "POLE_Elbow_R": "FK-TO-IK-SNAP_POLE_ELBOW_R",
- "CTRL_FOOT_R": "FK-TO-IK-SNAP_CTRL_FOOT_R",
- "POLE_Knee_R": "FK-TO-IK-SNAP_POLE_KNEE_R",
- }
- def snap_and_bake(snap_map):
- obj = bpy.context.object
- if obj.mode != 'POSE':
- bpy.ops.object.mode_set(mode='POSE')
- frame = bpy.context.scene.frame_current
- for target_bone, source_bone in snap_map.items():
- try:
- pbone = obj.pose.bones[target_bone]
- source = obj.pose.bones[source_bone]
- # Add Copy Transforms
- constraint = pbone.constraints.new(type='COPY_TRANSFORMS')
- constraint.name = "TEMP_Snap"
- constraint.target = obj
- constraint.subtarget = source.name
- # Select the bone
- for b in obj.data.bones:
- b.select = False
- obj.data.bones[target_bone].select = True
- bpy.context.view_layer.objects.active = obj
- # Bake the frame
- bpy.ops.nla.bake(
- frame_start=frame,
- frame_end=frame,
- only_selected=True,
- visual_keying=True,
- clear_constraints=False,
- clear_parents=False,
- use_current_action=True,
- bake_types={'POSE'}
- )
- # Remove ONLY the Copy Transforms constraint we just added
- for con in reversed(pbone.constraints):
- if con.type == 'COPY_TRANSFORMS' and con.name == "TEMP_Snap":
- pbone.constraints.remove(con)
- break
- except KeyError:
- print(f"Bone {target_bone} or {source_bone} not found, skipping.")
- # --- Run based on selection
- def main():
- selected = [b.name for b in bpy.context.selected_pose_bones]
- to_run = {}
- # Handle IK to FK
- for tgt, src in ik_to_fk_map.items():
- if tgt in selected or src in selected:
- to_run[tgt] = src
- # Handle FK to IK
- for tgt, src in fk_to_ik_map.items():
- if tgt in selected or src in selected:
- to_run[tgt] = src
- snap_and_bake(to_run)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement