Notifications
Clear all

[Closed] How can I transfer adding animation

Should I do it this way?

selectkeys $Teapot001.rotation.controller
copyPasteKeys $box001.rotation.controller ??? #insertkeys

2 Replies

You can try this function. Arguments descriptions:

  • “source” – animated object which contains keys that you need to transfer onto “target” object
  • “target” – not animated or animated object which will recive keys from “source” object
  • ” transPos” – can be ON or OFF. If ON then transfer position keys
  • ” transRot” – can be ON or OFF. If ON then transfer rotation keys
  • ” transScal” – can be ON or OFF. If ON then transfer scale keys
  • “timeOffset” – offset animation time. Default 0 frame
  • “replaceKeys” – can be ON or OFF. If on then replace existing keys of “target” object or
    if OFF then append new keys.

 fn transferKeys source target transPos:on transRot:on transScal:on timeOffset:0 replaceKeys:on =
 (
 	local keys
 	if timeOffset != 0 do source = copy source isHidden:on name:"SourceClone"
 	if transPos do
 	(
 		local sourcePosCtrl = if isKindOf source.pos.track Position_List then source.pos.track.active else source.pos.track
 		local targetPosCtrl = if isKindOf target.pos.track Position_List then target.pos.track.active else target.pos.track
 		if (e = sourcePosCtrl.numsubs) == 0 then
 		(
 			if replaceKeys do deleteKeys targetPosCtrl #allKeys
 			if (number = sourcePosCtrl.keys.count) != 0 do
 			(
 				keys = sourcePosCtrl.keys
 				for i = 1 to number do appendKey targetPosCtrl.keys (keys[i].time += timeOffset ; keys[i])
 				sortKeys sourcePosCtrl
 			)
 		)
 		else
 		(
 			for i = 1 to e do
 			(
 				if replaceKeys do deleteKeys targetPosCtrl[i] #allKeys
 				if (number = sourcePosCtrl[i].keys.count) != 0 do
 				(
 					keys = sourcePosCtrl[i].keys
 					for j = 1 to number do appendKey targetPosCtrl[i].keys (keys[j].time += timeOffset ; keys[j])
 					sortKeys sourcePosCtrl[i]
 				)			
 			)
 		)
 	)
 	if transRot do
 	(
 		local sourceRotCtrl = if isKindOf source.rotation.track Rotation_List then source.rotation.track.active else source.rotation.track
 		local targetRotCtrl = if isKindOf target.rotation.track Rotation_List then target.rotation.track.active else target.rotation.track
 		if (e = sourceRotCtrl.numsubs) == 0 then
 		(
 			if replaceKeys do deleteKeys targetRotCtrl #allKeys
 			if (number = sourceRotCtrl.keys.count) != 0 do
 			(
 				keys = sourceRotCtrl.keys
 				for i = 1 to number do appendKey targetRotCtrl.keys (keys[i].time += timeOffset ; keys[i])
 				sortKeys targetRotCtrl
 			)
 		)
 		else
 		(
 			for i = 1 to e do
 			(
 				if replaceKeys do deleteKeys targetRotCtrl[i] #allKeys
 				if (number = sourceRotCtrl[i].keys.count) != 0 do
 				(
 					keys = sourceRotCtrl[i].keys
 					for j = 1 to number do appendKey targetRotCtrl[i].keys (keys[j].time += timeOffset ; keys[j])
 					sortKeys targetRotCtrl[i]
 				)			
 			)
 		)
 	)
 	if transScal do
 	(
 		local sourceScaleCtrl = if isKindOf source.scale.track Scale_List then source.scale.track.active else source.scale.track
 		local targetScaleCtrl = if isKindOf target.scale.track Scale_List then target.scale.track.active else target.scale.track
 		if (e = sourceScaleCtrl.numsubs) == 0 then
 		(
 			if replaceKeys do deleteKeys targetScaleCtrl #allKeys
 			if (number = sourceScaleCtrl.keys.count) != 0 do
 			(
 				keys = sourceScaleCtrl.keys
 				for i = 1 to number do appendKey targetScaleCtrl.keys (keys[i].time += timeOffset ; keys[i])
 				sortKeys sourceScaleCtrl
 			)
 		)
 		else
 		(
 			for i = 1 to e do
 			(
 				if replaceKeys do deleteKeys targetScaleCtrl[i] #allKeys
 				if (number = sourceScaleCtrl[i].keys.count) != 0 do
 				(
 					keys = sourceScaleCtrl[i].keys
 					for j = 1 to number do appendKey targetScaleCtrl[i].keys (keys[j].time += timeOffset ; keys[j])
 					sortKeys sourceScaleCtrl[i]
 				)			
 			)
 		)
 	)
 	if isValidNode $SourceClone do delete $SourceClone
 )
 

 fn transferKeys source target transPos:on transRot:on transScal:on timeOffset:0 replaceKeys:on =
 (
 	local keys
 	if timeOffset != 0 do source = copy source isHidden:on name:"SourceClone"
 	if transPos do
 	(
 		local sourcePosCtrl = if isKindOf source.pos.track Position_List then source.pos.track.active else source.pos.track
 		local targetPosCtrl = if isKindOf target.pos.track Position_List then target.pos.track.active else target.pos.track
 		if (e = sourcePosCtrl.numsubs) == 0 then
 		(
 			if replaceKeys do deleteKeys targetPosCtrl #allKeys
 			if (number = sourcePosCtrl.keys.count) != 0 do
 			(
 				keys = sourcePosCtrl.keys
 				for i = 1 to number do appendKey targetPosCtrl.keys (keys[i].time += timeOffset ; keys[i])
 				sortKeys sourcePosCtrl
 			)
 		)
 		else
 		(
 			for i = 1 to e do
 			(
 				if replaceKeys do deleteKeys targetPosCtrl[i] #allKeys
 				if (number = sourcePosCtrl[i].keys.count) != 0 do
 				(
 					keys = sourcePosCtrl[i].keys
 					for j = 1 to number do appendKey targetPosCtrl[i].keys (keys[j].time += timeOffset ; keys[j])
 					sortKeys sourcePosCtrl[i]
 				)			
 			)
 		)
 	)
 	if transRot do
 	(
 		local sourceRotCtrl = if isKindOf source.rotation.track Rotation_List then source.rotation.track.active else source.rotation.track
 		local targetRotCtrl = if isKindOf target.rotation.track Rotation_List then target.rotation.track.active else target.rotation.track
 		if (e = sourceRotCtrl.numsubs) == 0 then
 		(
 			if replaceKeys do deleteKeys targetRotCtrl #allKeys
 			if (number = sourceRotCtrl.keys.count) != 0 do
 			(
 				keys = sourceRotCtrl.keys
 				for i = 1 to number do appendKey targetRotCtrl.keys (keys[i].time += timeOffset ; keys[i])
 				sortKeys targetRotCtrl
 			)
 		)
 		else
 		(
 			for i = 1 to e do
 			(
 				if replaceKeys do deleteKeys targetRotCtrl[i] #allKeys
 				if (number = sourceRotCtrl[i].keys.count) != 0 do
 				(
 					keys = sourceRotCtrl[i].keys
 					for j = 1 to number do appendKey targetRotCtrl[i].keys (keys[j].time += timeOffset ; keys[j])
 					sortKeys targetRotCtrl[i]
 				)			
 			)
 		)
 	)
 	if transScal do
 	(
 		local sourceScaleCtrl = if isKindOf source.scale.track Scale_List then source.scale.track.active else source.scale.track
 		local targetScaleCtrl = if isKindOf target.scale.track Scale_List then target.scale.track.active else target.scale.track
 		if (e = sourceScaleCtrl.numsubs) == 0 then
 		(
 			if replaceKeys do deleteKeys targetScaleCtrl #allKeys
 			if (number = sourceScaleCtrl.keys.count) != 0 do
 			(
 				keys = sourceScaleCtrl.keys
 				for i = 1 to number do appendKey targetScaleCtrl.keys (keys[i].time += timeOffset ; keys[i])
 				sortKeys sourceScaleCtrl
 			)
 		)
 		else
 		(
 			for i = 1 to e do
 			(
 				if replaceKeys do deleteKeys targetScaleCtrl[i] #allKeys
 				if (number = sourceScaleCtrl[i].keys.count) != 0 do
 				(
 					keys = sourceScaleCtrl[i].keys
 					for j = 1 to number do appendKey targetScaleCtrl[i].keys (keys[j].time += timeOffset ; keys[j])
 					sortKeys sourceScaleCtrl[i]
 				)			
 			)
 		)
 	)
 	if isValidNode $SourceClone do delete $SourceClone
 )
 

You’re great. Thank you very much.