jberns Posted August 2, 2018 Share Posted August 2, 2018 Community, I am a long-time developer of simple AutoLISP code. I am well familiar with local/global parameters in functions. As of late, I have been asked to develop commands with dialog box (DCL) interfaces. Will standard local parameter practices apply when developing code for use with DCL dialogs, or will global parameters be required? Thank you for your time and attention. I look forward to your replies. Regards, Jerry Quote Link to comment Share on other sites More sharing options...
rlx Posted August 2, 2018 Share Posted August 2, 2018 think best place to start is : http://web2.iadfw.net/terrycad/Tutorials/MyDialogs.htm Quote Link to comment Share on other sites More sharing options...
jberns Posted August 2, 2018 Author Share Posted August 2, 2018 Rlx, Thanks for the quick response. That link appears to be a great source of information. I will review and report back if I have more questions. Kind regards, Jerry Quote Link to comment Share on other sites More sharing options...
BIGAL Posted August 3, 2018 Share Posted August 3, 2018 Here is a quick one 3 DCL's input for 1,2 or 3 lines of input runs as a library routine external can be used with any code. ; your code here ;need 3 values inputed (if (not AH:getval3)(load "getvals3")) (ah:getval3 "Enter Horizontal scale " 5 4 "100" "Enter Vertical scale" 5 4 "50" "Enter number of decimal places" 5 4 "2") (setq horiz (atof val1)) (setq vert (atof val2)) (setq prec (atoi val3)) GETVALS3.lsp Quote Link to comment Share on other sites More sharing options...
jberns Posted August 3, 2018 Author Share Posted August 3, 2018 Thank you, Al. I ran the first example, but received an error. See attachement. Otherwise, these appear to be useful examples. I really like the idea of on-demand DCL file creation. One less file to manage. Is it best practice to automatically remove the file at the end of the function or let the user take care of it when they clean their Temp folder? I noticed that the parameter, dcl_id, was left global. Intentional? Required? Thanks again, Al, for the examples and quick response. Kind regards, Jerry Quote Link to comment Share on other sites More sharing options...
jberns Posted August 3, 2018 Author Share Posted August 3, 2018 I have corrected the DCL error (that was my fault). When running the first example, (ah:getval1 "Line 1" 5 4 default), this error results: "; error: bad argument type: stringp nil" Debugging now. Regards, Jerry Quote Link to comment Share on other sites More sharing options...
Steven P Posted August 3, 2018 Share Posted August 3, 2018 Thank you, Al. Is it best practice to automatically remove the file at the end of the function or let the user take care of it when they clean their Temp folder? I'm not sure if it is best practice but I have started specifying the name of my temp files, and ignoring the delete part. When the user runs the LISP again the file is simply overwritten. Since you'll only ever have 1 file (per DCL?) in the temp folder you aren't going to fill it up if the delete command doesn't work for some reason (crashes and so on), I can specify a name so if there is an error in the DCL I know what file to open, and a couple of other reasons. Each temp DCL file has its own name. Quote Link to comment Share on other sites More sharing options...
jberns Posted August 3, 2018 Author Share Posted August 3, 2018 In Al's example, a unique DCL file is being created each time. This could generate a lot of files depending upon use. I am not sure sure if this was intended by Al or a circumstance of my environment (AutoCAD version, OS, etc.) - Jerry Quote Link to comment Share on other sites More sharing options...
jberns Posted August 3, 2018 Author Share Posted August 3, 2018 Good news, error resolved. I needed to change, default, to an actual string. For example, (ah:getval1 "Line 1" 5 4 "Test"). And, the temp file erased itself after the dialog closed. Automatic clean-up - terrific!! - Jerry Quote Link to comment Share on other sites More sharing options...
BIGAL Posted August 6, 2018 Share Posted August 6, 2018 The code was written originally hardcoded to a temp directory but it was changed as I kept getting user errors when posted here because the directory did not exist. The (vl-file-delete fname) deletes the file. ; sample [b](ah:getval1 "Line 1" 5 4 [i]"Default value as string"[/i])[/b]. ; you can hard code a directory if you like for dcl file ;(setq fo (open (setq fname "c:\\acadtemp\\getvals.dcl") "w")) (setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w")) There is lots of dcl stuff out there that you can use a library call, so not in each bit of code, Lee-mac has some good ones. Grr has a nice dcl array that can be different sizes, the getvals can be expanded further I have 1-8, you can also do single lips that takes a list and works out the number of rows required, I am not sure of the maximum number but 8 works. Here is a variation on a initget using radio buttons good for X or Y etc forcing a user to only respond with 1 correct answer. (defun AH:CIVPTHT (/ fo fname) (setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w")) (write-line "Civilcad_ptht : dialog {" fo) (write-line (strcat " label =" (chr 34) "Civilcad Pt hts" (chr 34) " ;" )fo) (write-line " : row {" fo) (write-line " : boxed_radio_column {" fo) (write-line (strcat " label = "(chr 34) "Pt or All" (chr 34) " ;") fo) (write-line " : radio_button {" fo) (write-line (strcat "key = " (chr 34) "rb1" (chr 34) ";") fo) (write-line (strcat "label = " (chr 34) "1 pt" (chr 34) ";") fo) (write-line " }" fo) (write-line " : radio_button {" fo) (write-line (strcat " key = " (chr 34) "rb2" (chr 34) ";") fo) (write-line (strcat " label = "(chr 34)"All" (chr 34) ";") fo) (write-line " }" fo) (write-line " }" fo) (write-line " }" fo) (write-line " ok_only;" fo) (write-line " }" fo) (close fo) (setq dcl_id (load_dialog fname)) (if (not (new_dialog "Civilcad_ptht" dcl_id) ) (exit) ) (action_tile "rb1" "(setq val1 $value)") (action_tile "rb2" "(setq val2 $value)") (start_dialog) (done_dialog) (unload_dialog dcl_id) (vl-file-delete fname) ) ; defun ; check val1 val2 etc Quote Link to comment Share on other sites More sharing options...
jberns Posted August 6, 2018 Author Share Posted August 6, 2018 Thanks, Al, for the clarification and additional example. Regards, Jerry Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.