Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Copyright (c) [2/25/24] [Dieton]
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- !!!Warning!!!
- This is VERRY SLOW if you are doing this on a lot of objects or bones and frames
- This script sets keyframes on every frame of all selected object set bellow
- """
- import bpy
- def set_keyframes(start_frame, end_frame):
- # Get the selected pose bones
- selected_pose_bones = bpy.context.selected_pose_bones
- # Check if any pose bones are selected
- if not selected_pose_bones:
- print("Error: No pose bones selected.")
- return
- # Iterate through selected pose bones
- for bone in selected_pose_bones:
- # Store initial transforms
- initial_location = bone.location.copy()
- initial_rotation = bone.rotation_quaternion.copy() if bone.rotation_mode == 'QUATERNION' else bone.rotation_euler.copy()
- initial_scale = bone.scale.copy()
- # Set keyframes at every frame from start to end frame
- for frame in range(start_frame, end_frame + 1):
- bpy.context.scene.frame_set(frame)
- bone.location = initial_location
- if bone.rotation_mode == 'QUATERNION':
- bone.rotation_quaternion = initial_rotation
- else:
- bone.rotation_euler = initial_rotation
- bone.scale = initial_scale
- bone.keyframe_insert(data_path="location", index=-1)
- if bone.rotation_mode == 'QUATERNION':
- bone.keyframe_insert(data_path="rotation_quaternion", index=-1)
- else:
- bone.keyframe_insert(data_path="rotation_euler", index=-1)
- bone.keyframe_insert(data_path="scale", index=-1)
- # Reset transforms to initial values
- bone.location = initial_location
- if bone.rotation_mode == 'QUATERNION':
- bone.rotation_quaternion = initial_rotation
- else:
- bone.rotation_euler = initial_rotation
- bone.scale = initial_scale
- # Set your desired start and end frames
- start_frame = 1
- end_frame = 60
- # Call the function to set keyframes
- set_keyframes(start_frame, end_frame)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement