stuh505
03-19-2009, 11:58 PM
I've written this (pretty handy) script which saves the camera parameters of an animation. When I run the script, it always fails to create a file on the first attempt, but then it works on the second (or third or fourth...) attempt.
The problem seems to be that max script tries to execute the "if output_name != undefined" before I have time to select a file name. What am I doing wrong?
output_name = getSaveFileName caption:"Animation Camera Parameters" types:"Text (*.txt)|*.txt|All Files (*.*)|*.*|"
if output_name != undefined then
(
output_file = createfile output_name
cam = cameras[1]
format "frame, pix_width, pix_height, fov_w, Zn, Zf, RightX, RightY, RightZ, DownX, DownY, DownZ, ForX, ForY, ForZ, cam_x, cam_y, cam_z\n" to:output_file
for frame=animationRange.start to animationRange.end do
(
sliderTime = frame
vRight = cam.transform[1]
vDown = -cam.transform[2]
vForward = -cam.transform[3]
format "% % % % % % % % % % % % % % % % % %\n" frame renderWidth renderHeight cam.fov cam.nearclip cam.farclip vRight.x vRight.y vRight.z vDown.x vDown.y vDown.z vForward.x vForward.y vForward.z cam.pos.x cam.pos.y cam.pos.z to:output_file
)
close output_file
)
The problem seems to be that max script tries to execute the "if output_name != undefined" before I have time to select a file name. What am I doing wrong?
output_name = getSaveFileName caption:"Animation Camera Parameters" types:"Text (*.txt)|*.txt|All Files (*.*)|*.*|"
if output_name != undefined then
(
output_file = createfile output_name
cam = cameras[1]
format "frame, pix_width, pix_height, fov_w, Zn, Zf, RightX, RightY, RightZ, DownX, DownY, DownZ, ForX, ForY, ForZ, cam_x, cam_y, cam_z\n" to:output_file
for frame=animationRange.start to animationRange.end do
(
sliderTime = frame
vRight = cam.transform[1]
vDown = -cam.transform[2]
vForward = -cam.transform[3]
format "% % % % % % % % % % % % % % % % % %\n" frame renderWidth renderHeight cam.fov cam.nearclip cam.farclip vRight.x vRight.y vRight.z vDown.x vDown.y vDown.z vForward.x vForward.y vForward.z cam.pos.x cam.pos.y cam.pos.z to:output_file
)
close output_file
)
