How To ... Output Object Data To File
macroScript SpeedSheet category: "HowTo"
(
if selection.count > 0 then
(
output_name = getSaveFileName caption: "SpeedSheet File" types: "SpeedSheet (*.ssh)|*.ssh|All Files (*.*)|*.*|"
if output_name != undefined then
(
output_file = createfile output_name
at time animationrange.start format "Object(s): %/n" (selection as array) to :output_file
average_speed = 0 --平均速度
for t = animationrange.start to animationrange.end do
(
at time t current_pos = selection.center
at time (t-1f) last_pos = selection.center
frame_speed = (distance current_pos last_pos)*FrameRate --帧速
average_speed += frame_speed
format "Frame %: %/n" t frame_speed to :output_file
)
average_speed /= (animationrange.end-animationrange.start)
format "Average Speed: %/n" average_speed to :output_file
close output_file
edit output_name
) --end if
) --end if
) --end macroScript
运行结果:
==================================
animationrange 默认为100帧
FrameRate 帧速率 这里是30
有一行代码让我思索好久,最后恍然大悟
frame_speed = (distance current_pos last_pos)*FrameRate
一直想为什么乘呢?
原来1秒有30帧