findfile function to search for a particular file name. The application can specify the directory to search, or it can use the current AutoCAD library path.
An application can use thefindfile searches for the requested file name according to the AutoCAD library path:
In the following code fragment,(setq refname "refc.dwg")
(setq fil (findfile refname))
(if fil
(setq refname fil)
(princ (strcat "\nCould not find file " refname ". " ))
)
findfile is successful, the variable refname is set to a fully qualified path name string, as follows:
If the call to"/home/work/ref/refc.dwg"
\)with another backslash so the path name will be recognized by AutoLISP. Alternatively, you can use the slash character (/) as a directory separator.
When specifying a path name, you must precede the backslash (getfiled function displays a dialog box containing a list of available files of a specified extension type in the specified directory. This gives AutoLISP routines access to the AutoCAD Get File dialog box.
Thegetfiled takes four arguments that determine the appearance and functionality of the dialog box. The application must specify the following string values, each of which can be nil: a title, placed at the top of the dialog box; a default file name, displayed in the edit box at the bottom of the dialog box; and an extension type, which determines the initial files provided for selection in the list box. The final argument is an integer value that specifies how the dialog box interacts with selected files.
A call togetfiled to let you view your directory structure and select a file:
This simple routine uses(defun C:DDIR ( )
(setq dfil (getfiled "Directory Listing" "" "" 2))
(princ (strcat "\nVariable 'dfil' set to selected file " dfil ))
(princ)
)
dfil variable is set to the file you select, which can then be used by other AutoLISP functions or as a response to a command line prompt for a file name. To use this variable in response to a command line prompt, enter !dfil.
This is a useful utility command. Thegetfiled in the AutoLISP Reference.
For more information, see