fn shiftroll fin obj =
(
  format "obj = %\n" obj
  local mat=#()
  mat[1]=" "
  local matrix3 matstart
  while not eof fin do(
    s=readLine fin
	if findString s "#()" != undefined then(
	   mat=filterString s " "
	   exit
	)
  )
  format "matr = %\n" mat[1]
  /*local k=execute(mat[1]+".count")*/
  format "matcount = % \n" k
  /*execute("matstart="+mat[1]+"[1]")
  format "matstart = % % \n" matstart mat[1]*/
  obj1=execute obj
  /*rotate obj1 (inverse matstart.rotationpart)*/
  local index=0
  local	matr=#()
  while not eof fin do(
    s=readLine fin
	if findString s "mt=angle" != undefined then(
	  execute(s)
	  execute(readLine fin)
	  execute(readLine fin)
	  index=index+1
	  matr[index]=mt
	)
  )
  format "index====% %\n" index obj1
  rotate obj1 (inverse obj1.rotation)
  rotate obj1 matr[1].rotationpart
  obj1.pos=matr[1].translationpart
  execute("deleteKeys "+obj)
    animate on(
    for i=2 to index do (
      at time (i-1) (
        rotate obj1 (inverse matr[i-1].rotationpart)
        rotate obj1 matr[i].rotationpart
        obj1.pos=matr[i].translationpart
      )
    )
  )
  format "end %\n" index
)

global setanimation
rollout setanimation "назначить анимацию" width:250 height:230
(
	button btn "select file" pos:[100,100] width:100 height:30
	on btn pressed do 
	(
	  local error1
	  local index
	  fnn = getOpenFileName caption:"select files" types:"scripts (*.mcr)|*.mcr"
	  if fnn != undefined then(
	    f=openFile fnn mode:"rt"
		if f != undefine then(
	      base=$*Shape* as array
          index=0 
		  while not eof f do(
		    s=readLine f
            sm=filterString s " \""
			if sm.count != 2 then messageBox "illegal string at input file"
		    if findstring sm[2]  "3ds" != undefined then(
			  print sm[2]
              fin=openfile sm[2] mode:"rt"
			  for i=index+1 to base.count do(
			    sn=filterString (base[i] as string)  "$ :"
				error1=1
				if execute("$"+sn[2]+".parent") == undefined then(
                  print ("$"+sn[2]+".parent")
				  index=i
				  error1=0
				  animate off
				  shiftroll fin ("$"+sn[2])
				  exit 
				)
     		  )
			  close fin
			  if error1 != 0 then(
			    messageBox "too few bodies at current scene"
				exit  
			  )
		    )
		  )	
		  close f
    	  for i=index+1 to base.count do(
	 	    sn=filterString (base[i] as string)  "$ :"
		    if execute("$"+sn[2]+".parent") == undefined then(
              print ("$"+sn[2]+".parent")
			  messageBox "too few bodies at script file"
              exit 
		    )
          )		  
		)
		else(
		  messageBox "cannot open file"
		)

	  ) 
	)
)
CreateDialog setanimation width:250 height:230

