copy paste number of keyframe mel script


#1

Hello
I need a tool that can with eat take all the keyframe number of an animated object and past it to a new object. i just want to past the keyframe number. for exemple if i have a first animated object named Cube1 and has an animation at keyframe number 10 - 15 - 30 - 50. i want that object two take keyframe at 10 - 15 - 30 - 50 but without change any of its attribute. i don’t now from where to start scripting this idea but i need it so much.


#2

Hi,

Hopefully this should get you started.

import maya.cmds as cmds

# Select the source object (object with keyframes), followed by the destination object (object to be keyed)
sourceObject, destinationObject = cmds.ls(sl=True)[0], cmds.ls(sl=True)[1]
# Get all keyframes for all animatable attributes
keyframes = cmds.keyframe(sourceObject, query=True)
# Remove duplicates
keyframes = list(set(keyframes))

# Loop through keyframe list
for i in range(len(keyframes)):
	# Set the current time
	cmds.currentTime(keyframes[i])
	# Set a keyframe on the current time
	cmds.setKeyframe(destinationObject)

Good luck!


#3

Thank you so much mlefevre this is exactly what i need. you save me lot of time. i don’t have any experience with python i know mel a little bit but that’s not a problem i test your python script just now and its works perfectly so thank you so much another time. :keenly: