PDA

View Full Version : Problem with getSaveFileName


stuh505
03-19-2009, 10: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
)

Gravey
03-20-2009, 01:04 AM
the problem might be with the createFile function. Personally i never use it, if i ever need to write to a file i use openFile <filename> mode:"w" which automatically creates the file if it doesnt exist and overrides if it does. note the mode:"w" which sets the read/write mode to write. i THINK that if you use the createFile function you then need to call the openFile function with mode:"w" immediatly after anyway. not tested but off the top of my head i think that's your problem

Bobo
03-20-2009, 02:16 AM
On first look, your code looks ok (except for being run in global scope which is not a cause of problem here).
I copied your code into a fresh editor, pressed Ctrl+E and it worked the FIRST time as expected.

Of course, I would have expected such code to be inside a MacroScript body as a toolbar button. So the question is - is this the whole code and how exactly do you run it?

thatoneguy
03-20-2009, 02:39 AM
I'm using createfile right now and as long as you do

var = createfile pathstring

it'll automatically open it.

CGTalk Moderation
03-20-2009, 02:39 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.