10 June 2013

getfiled () function in AutoLISP

 Hi friends, in this article I will explain about getfiled ()  function in AutoLISP or how to Prompts the user for a file name with the standard AutoCAD file dialog box, and returns that file name in AutoLISP.
Name: getfiled
Syntax:
(getfiled title default ext [flag])
Description:
By using this function when we click on the button then it will opens a dialog box, through this user can select the file what he want to open easily. Displays a common Windows file browse box. You can use more than one flag by adding them to get such as 1 and 4 you would use a 5. Multiple extensions can be displayed in the drop down when they are separated with a semi-colon.
Flag
Meaning
1
Create new filename
2
Disable "Type It" button
4
Any extension is allowed
8
Search for filename
16
Second argument acts like a path or directory
32
Inhibits alert box from being displayed.

Examples:
(setq dfil (getfiled "Select A Directory" "c:\\Temp" "dwg" 0))
(setq dfil (getfiled "Select A Directory" "c:\\Temp\\" "dwg" 0))
                       First of all open the Visual LISP Editor, if you want to know about how to open Visual LISP Editor in AutoCAD. Write the following.
I explain this function using a small example.
I create one button in .DCL file like below figure.
When we click on file button it will open below dialog box.

The code for DCL file is

GetFile : dialog {

label = "Get File";
:row{
     :button {
                      label = "File...";
                             key = "file";
                             fixed_width = true;
                     }

                     }
                     ok_cancel;
                     }

And the code for  lisp file is

(defun c:getfile()
  (setq dcl_id (load_dialog "file.dcl"))
(if (not (new_dialog "GetFile" dcl_id))(exit))
 (action_tile "file" "(get_file)")
 (action_tile "accept" "")
 (action_tile "cancel" "(done_dialog)")
 (start_dialog)
 (unload_dialog dcl_id)
 (setq f1 (open f2 "r"))
)
;;;;;;;;Get_file
(defun get_file()
(setq filename "txt")
(setq path (getfiled "Autolisp-Roja's Browser" "C:\\" filename 2))
(setq dir (car (fnsplitl path)))
(setq file (cadr (fnsplitl path)))
(setq f2 (strcat dir file ".txt"))
)

In the above lisp code f2 will give the path of the file. Using f2 we can do what u want.
Thanks for reading my blog. If you have any doubts, appreciation then please put the doubt or appreciation as a comment.
Thank you for reading my blog AutoLISP-Roja..If you like my blog please like the facebook page AutoLISPRoja


No comments:

Post a Comment