/* getpoints.rexx */
/* get vertices for particle animation */
address "LWModelerARexx.port"
libadd = addlib("LWModelerARexx.port",0)
SIGNAL ON ERROR
SIGNAL ON SYNTAX
MATHLIB="rexxmathlib.library"
IF POS(MATHLIB , SHOW('L')) = 0 THEN
  IF ~ADDLIB(MATHLIB , 0 , -30 , 0) THEN DO
   call notify(1,"!Can't find "MATHLIB)
   exit
   END
type = 1
call req_begin "Grab Particle Positions"

id_txt = req_addcontrol("Choose source or target", 'T', "position")
id_type = req_addcontrol("", 'CH','Source Target')

call req_setval id_type, type

if (~req_post()) then do
  call req_end
  req=0
  exit
  end

type =req_getval(id_type)
call req_end


If type = 1 then do
File.name = 't:Source'
end
If type = 2 then do
  File.name = 't:Target'
end
t=time('e')
n = xfrm_begin()

 call meter_begin n+1 , "Grabbing "n" points," ,"  Be right with you."
do i = n to 1 by -1
/* say i */
  parse value xfrm_getpos(i) with x y z .
If i = n  Then do
      call writeheader(mot,x ||" "|| y ||" "|| z)
   End
If i < n then do
      call writekey(mot,x ||" "|| y ||" "|| z)
  end
 call meter_step
end
call xfrm_end
call meter_end
call close mot
t=time('e')-t
say 'Whew, I just transformed 'n' points in only 't' seconds.'
call notify(1,'!Holy Smoke, I just grabbed 'n' points','!in only 't'
seconds.')
if (libadd) then call remlib("LWModelerARexx.port")

Exit

Writekey: PROCEDURE EXPOSE i x y z.
  arg MotFile, Keys
    call writeln(MotFile,Keys)

  return 1


WriteHeader: PROCEDURE EXPOSE file.
  arg MotFile, keys
if open(MotFile,File.name,'W') then do
    call writeln(MotFile,keys)
 end
  else do
say    "Bummer Can't open Motion file ; "|| File.name
  end
  return 1

SYNTAX:
ERROR:
  say 'Sorry, Error #'RC' on line 'SIGL' has been detected.'
  say errortext(rc)
  say sourceline(SIGL)
  t=notify(1,'!Total Bummer Dude!','!An error has been detected.','@'ErrorText(rc),'Line 'SIGL)
  call end_all
  exit
