File I/O File Request 2 Globals Table of Contents

File Request

Availability  LightWave® 6.0
Component  Layout, Modeler
Header  lwhost.h

The file request global returns a function that prompts the user for a file selection. The request displays the file dialog currently installed in LightWave®. This may be the default system dialog or a custom file dialog plug-in. See the File Request 2 global for a newer interface to the file dialog mechanism.

Global Call

   LWFileReqFunc *filereq;

The global function returns a pointer to an LWFileReqFunc.

   typedef int LWFileReqFunc (const char *hail, char *name, char *path,
      char *fullName, int buflen);
The title string. This is generally displayed near the top of the file dialog and tells the user what kind of file is being requested.

The initial file name, not including the path. This can be empty, or it can contain a default name. It can also contain file type patterns that on most systems will filter the names displayed in the dialog. Pattern strings for certain types of files can be obtained from the File Type Pattern global. If you construct your own pattern strings, remember that these are platform-specific and may also be locale-specific.

Some systems display different dialogs for loading and saving. If the first character of the name is '<', a load dialog will be displayed, and if it's '>', a save dialog will be displayed. These initial characters won't appear as part of the initial name or file type pattern.

If the user selects a file, the initial name is replaced with the name (not including the path) of the selected file.

The initial path. Default paths for certain file types can be obtained from the Directory Info global. If you construct your own path string, remember that path lexics depend on the platform. If the user selects a file, the initial path is replaced with the path of the selected file.

The file request returns the selected file name, including the path, in this string. The initial contents are ignored.

The size in bytes of the name, path and fullName strings. Note that all of them must be at least this size and must be large enough to hold the largest file name string you expect to process (a minimum of 256 bytes is recommended).


This code fragment asks the user for the name of a file to save.

   #include <lwhost.h>
   #define MAXFILESZ 260

   static char
      node[ MAXFILESZ ] = "",
      path[ MAXFILESZ ] = "",
      name[ MAXFILESZ ] = "";

   LWFileReqFunc *filereq;
   LWMessageFuncs *message;
   int result;

   if ( !filereq || !message ) return AFUNC_BADGLOBAL;

   result = filereq( "Save Widget", node, path, name, MAXFILESZ );
   if ( result ) {
      save_widget( widget, name );
      message->info( "The widget has been saved to", node );
      /* the user cancelled the file dialog */