6.4.1 Filename write
By default, generator output is directed to a Generator Output
tool, from which it can be printed, saved to a file, or copied and pasted to
another application. Generator output can also be directed to a file, and
different parts of the output can be written to different files:
filename 'name.txt' write
/* generator output commands here */
close
Between
filename and
write there can be any generator
commands, all of whose output goes to building up the filename to be used. There
are also two useful commands here to prompt for the file name from the user. The
first command, prompt...ask, opens a
dialog asking the user for a string, and then outputs that string: this then is
used in building up the filename, just as any output from any other
keyword:
filename
prompt
'Enter file to output '
id
' to?'
ask
write
/* generator output commands here */
closeThe filename can also include information about
directory paths.
The second command,
prompt...askFilename, behaves similarly
to prompt...ask but instead of
prompting for a simple string, it provides a full file dialog. This enables the
user not only to enter the filename but also to create new folders or select an
existing filename.
All commands between
write and
close will output to the file
specified. The close keyword
immediately closes the output stream and writes the file. Commands after
close will send their output to
whichever output stream was in force before the
filename command.
At the end of the whole generator a dialog will show how
many characters were written to each file. If an error occurs trying to write to
a file, the dialog will show the error message and output for that file will be
redirected to its own Generator Output
tool.