AutoKey - Animation Converter(Dev)

Hi, i'm trying to remake AutoKey script, it's currently able to copy from one object to another - exact same XYZ position key's.
But problem is that i have a rigged skeleton with animation and it has about 30+ bones and script can't work with more then 2 objects( 1 without anim and 2 with anim)
This is what i was able to do

on alignSource pressed do
	(	
		(
		sticks = #()
		append sticks $ 
		)
		for i = 1 to sticks.count do
 
		(global object1 = sticks[i]
		 objNames = for obj in selection collect obj.name
		objNames = makeUniqueArray objNames
		uniObjs = objNames as string
			AlignSource.text = uniObjs
 
 
 
 
 
		)
	)
	on alignDest pressed  do
		(	
		(
		vecs = #()
		append vecs $ 
		)
		for i = 1 to vecs.count do
 
		(global object2 = vecs[i]
		 objNames = for obj in selection collect obj.name
		objNames = makeUniqueArray objNames
		uniObjs = objNames as string
		alignDest.text = uniObjs
 
		)
	)
 
)

The result is same(working with 1 selecetion on each menu) only change is that http://i.shotnes.com/a/09/zw1rkbus.ko3_522e5062a76e4.png
object's that where seleceted are displaying in text box.

But if there is more then 2 objects selected i get this error.

If you can help with it please, i waisted a lot of time on this issue and ruined a project because of time it taked.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

...

First of all to collect objects in arr1 or arr2 u cal simply use

local arr1 = selection as array 
-- or 
local arr1 = getCurrentSelection()

Now check if arr1 and arr2 count is greater then zero and if both count are equal.
Then you can use this fn to copy separately pos, rot or scale keys.
This is your tool

try(destroyDialog ::bgaRoll)catch()
rollout bgaRoll "transferKeys"
(
	local animObjs = #(), statObjs = #()
	button btn_animO "Collect Animated Objects" pos:[5,5] width:140 height:18
	progressBar pb_ao color:black value:100 pos:[5,24] width:140 height:5
	button btn_statO "Collect Static Objects" pos:[5,30] width:140 height:18
	progressBar pb_so color:black value:100 pos:[5,49] width:140 height:5
	checkbox cb_pos "Pos" pos:[5,55] fieldwidth:20
	checkbox cb_rot "Rot" pos:[52,55] fieldwidth:20
	checkbox cb_scal "Scale" pos:[100,55] fieldwidth:20
	button btn_trans "Transfer Keys" pos:[5,72] width:140
 
	fn transferKeys arr1 arr2 pos:cb_pos.checked rot:cb_rot.checked scal:cb_scal.checked = 
	(	
		if arr1.count != 0 and arr2.count != 0 and arr1.count == arr2.count do
		(
			local ctrl = #()
			if pos do append ctrl 1 ; if rot do append ctrl 2 ; if scal do append ctrl 3
			if ctrl.count != 0 do for a in 1 to arr1.count do
			(
				for c in ctrl do
				(
					for i = 1 to 3 do
					(
						if arr1[a][3][c][i].track.keys.count != 0 do
							arr2[a][3][c][i].track = copy arr1[a][3][c][i].track
					)
				)
			)
		)
	)	
	on btn_animO pressed do
	(
		animObjs = getCurrentSelection()
		if animObjs.count != 0 do pb_ao.color = red
		format "Animated Objects Count = %\n" animObjs.count
	)
	on btn_statO pressed do
	(
		statObjs = getCurrentSelection()
		if statObjs.count != 0 do pb_so.color = green
		format "Static Objects Count = %\n" statObjs.count
	)
	on btn_trans pressed do 
	(
		transferKeys animObjs statObjs
		pb_ao.color = pb_so.color = black
		free animObjs ; free statObjs
	)
)
createDialog bgaRoll 150 100 10 110 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

barigazy

barigazy's picture

...

How it works:
Select in order all animated objects in the scene and press "Collect Animated Objects". The same rule applies to static objects. Red and green progresbar shows that you are collected all objs that you need for now.
Check which controller keys you need to transfer (pos , rot , scale checkboxes) and press "Transfer Keys" button.
NOTE: Only controllers that contains animated keys will be transfered. Open Track Editor and see for yourself.
Cheers!

barigazy

DolVai's picture

Thx a lot barigazy,

Thx a lot barigazy, unfortunately it doesnt work for bones http://i.shotnes.com/a/17/orxbtoyj.io3_5237e7c744b44.png
these bones doesnt show keys in track view.
I'm trying to adopt your script for old one, which aligns pos and create keys, will give you video if i'l make it - thx a lot.

barigazy's picture

...

I know. I created the tool for your last example. Bones will never works with this method.

barigazy

DolVai's picture

Is it hard to make some

Is it hard to make some count'er for this part of code

if selRotation.checked do
(
in coordsys world x = object1.rotation
in coordsys world y = object2.rotation
in coordsys local object1.rotation = y - x
)
I tried to change object1 to what you said - getCurrentSelection, i get same result =(.

DolVai's picture

I figure it out anyway( By

I figured it out anyway( By myself)

--- add in sourcebutton;   global arr1 = for obj in selection collect obj
--- add in destbutton; 	global arr2 = for obj in selection collect obj
 
			if selPosition.checked do(
				for object1 in arr1 do 
 
(
  local pc = object1.position.controller
  for startFrame in object1.rotation.controller.keys do
    addNewKey pc startFrame.value
)
 
 
-----
 
if selPosition.checked do
			(
				if arr1.count == arr2.count do
				(
					for i = 1 to arr1.count do
 
					arr1[i].pos = arr2[i].pivot 
				)
			)
 

And thx barigazy, your script example rly help me out, now script is fully working.

 

DolVai's picture

So any advise ?script is

So any advise ?

script is working for arr2[i].pos = arr1[i].pos with for i = 1 to arr1.count do.

IT is not working with

startFrame.value = (startFrame.value - 1 )
		endFrame.value = endFrame.value
		done.text = "computing..."
		sliderTime = startFrame.value
		------------------------------------------------------------
			if selPosition.checked do addNewKey object1.position.controller startFrame.value
			if selRotation.checked do addNewKey object1.rotation.controller startFrame.value
			if selScale.checked do addNewKey object1.scale.controller startFrame.value
			startFrame.value += 1
			sliderTime += 1
			progress.value = ( 100 * startFrame.value ) / endFrame.value			

And i have no idea how to make it work with multiple objects in selection(X) to (Selection X)
The addkey animation feature is stoping after first object got keys(script won't addkey to second obj), any help ??

DolVai's picture

Thx i understand this for a

Thx i understand this for a bit the script that you send me, the thing i dont understand is that what do i need to make - an count'er, for amount of selected object,
so script would be appled to all of the objects in selection variable "A" to selection var "B" ?

and if it so how i need to make it properly in that script ?
like here

		if selPosition.checked do
			( 
                          for i = 1 to object1.count do
 
                         (object1.pos = object2.pivot)
 
			)

And here

if selPosition.checked then for i = 1 to object1.count do addNewKey object1.position.controller startFrame.value

? rly taked a lot of time on this =(.

The script itself for properly for 1 to 1 objects, it doesnt work if there is 2 to 1 or more.

barigazy's picture

...

Here another example

-- array of animated objects
arr1 = #($Source001,$Source002,$Source003,$Source004,$Source005)
-- array of objects that you need to copy animations
arr2 = #($Target001,$Target002,$Target003,$Target004,$Target005)
if arr1.count == arr2.count do
(
	for i = 1 to arr1.count do
	(
		arr2[i].pos = arr1[i].pos
		arr2[i].parent = arr1[i].parent
		(arr2[i])[3].track = (arr1[i])[3].track
 
	)
)

barigazy

DolVai's picture

Thx,but for my

Thx,
but for my script
http://i.shotnes.com/a/11/k12fylci.2fz_522fb49888740.png

this solutin cant be appled(For this script, the only reason i use it - it make perfect position and anim keys), it has 2 buttons, for storing selection for array 1 and array 2.

Then it has add key function http://i.shotnes.com/a/11/ymob5bxi.zh0_522fb558bc135.png

That is problem i guess, because it designed only to add key for 1 object(that where selected on alignObjects button.

Barigazy

Could you give me hint(script Code) how to add keys for bouth objects in selection 1 array.

If i'm wrong correct me, i'm less skilled in script writing.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.