tagkelas Posted April 8, 2010 Posted April 8, 2010 I have 3 lisp routines in one file For Example (defun c:demo1()...................) (defun c:demo2()...................) (defun c:demo3()...................) How Can I create a simple dialog box with the 3 lisp routines in a list box and two buttons ( OK & Cancel )? I want each time I choose, for ex. demo2, from the list box and by pressin OK, the "demo2" lisp routine start running... Sorry for my bad english.. Quote
alanjt Posted April 8, 2010 Posted April 8, 2010 Seems like a lot of legwork for something so simple. Why not just give a choice at the command line? (initget 0 "1 2 3") (setq demo (getkword "\nSpecify demo number [1/2/3]: ")) Quote
The Buzzard Posted April 8, 2010 Posted April 8, 2010 I have 3 lisp routines in one fileFor Example (defun c:demo1()...................) (defun c:demo2()...................) (defun c:demo3()...................) How Can I create a simple dialog box with the 3 lisp routines in a list box and two buttons ( OK & Cancel )? I want each time I choose, for ex. demo2, from the list box and by pressin OK, the "demo2" lisp routine start running... Sorry for my bad english.. Try this out, Make sure you keep both files together and the are in the ACAD Support Search Path. Just type Demo. Demo.dcl ///////////////////////////////////////////////////////////////////////////////////////////// DEMO : dialog { label = "Demo.lsp"; : column { : boxed_column { label = "Select a function:"; : popup_list { key = "FUNCT"; width = 18.0; fixed_width = true; alignment = centered; } : spacer { height = 0; } } : button { label = "&Ok"; key = "accept"; width = 18; fixed_width = true; alignment = centered; is_default = true; } : button { label = "&Exit"; key = "cancel"; width = 18; fixed_width = true; alignment = centered; is_cancel = true; } } } ///////////////////////////////////////////////////////////////////////////////////////////// Demo.lsp (defun C:DEMO (/ DCL_ID FUNCT FUNCT_LIST) (or F:UNCT (setq F:UNCT 0)) (setq FUNCT_LIST (list "Demo 1" "Demo 2" "Demo 3")) (setq DCL_ID (load_dialog "DEMO.dcl")) (if (not (new_dialog "DEMO" DCL_ID)) (exit)) (start_list "FUNCT")(mapcar 'add_list FUNCT_LIST)(end_list) (if F:UNCT-DEF (set_tile "FUNCT" (itoa F:UNCT-DEF))) (action_tile "accept" (strcat "(progn (setq F:UNCT (atoi (get_tile \"FUNCT\")) F:UNCT-DEF F:UNCT)" "(done_dialog)(setq button T))")) (action_tile "cancel" "(done_dialog)(setq button nil)") (start_dialog) (unload_dialog DCL_ID) (setq FUNCT F:UNCT) (if button (cond ((= FUNCT 0)(ALERT "You selected Demo 1")) ((= FUNCT 1)(ALERT "You selected Demo 2")) ((= FUNCT 2)(ALERT "You selected Demo 3")))) (princ)) Quote
tagkelas Posted April 8, 2010 Author Posted April 8, 2010 Seems like a lot of legwork for something so simple.Why not just give a choice at the command line? (initget 0 "1 2 3") (setq demo (getkword "\nSpecify demo number [1/2/3]: ")) If I wanted to do this at the command line I could simply write: demo1 or demo2 or..... The Buzzard I think this would be fine. Can I "put" the demo.dcl file inside the demo.lsp? Quote
Lee Mac Posted April 8, 2010 Posted April 8, 2010 But you still have to invoke a function to load the List_Box - what is the point? Quote
The Buzzard Posted April 8, 2010 Posted April 8, 2010 If I wanted to do this at the command line I could simply write: demo1 or demo2 or..... Which is it? Do you want a dialog? or Do you want to run from the command prompt? Quote
BearDyugin Posted April 8, 2010 Posted April 8, 2010 (initget 0 "1 2 3") (setq demo (getkword "\nSpecify demo number [1/2/3]: ")) But I prefer this way (initget "1 2 3") (setq demo (getkword "\nSpecify demo number [1/2/3] <1>: ")) Quote
The Buzzard Posted April 8, 2010 Posted April 8, 2010 If I wanted to do this at the command line I could simply write: demo1 or demo2 or..... The Buzzard I think this would be fine. Can I "put" the demo.dcl file inside the demo.lsp? If you compile it to an FAS fast load file, Then yes. Or it would need to be written differently into the lisp. I prefer the above method. Quote
Lee Mac Posted April 8, 2010 Posted April 8, 2010 This is how I might approach it (defun c:demo (/ dcl_write DATA DC FLAG PTR) (vl-load-com) (setq data '(("demo1" . (c:demo1)) ("demo2" . (c:demo2)) ("demo3" . (c:demo3)))) (defun dcl_write (fname / wPath ofile) (if (not (findfile fname)) (if (setq wPath (findfile "ACAD.PAT")) (progn (setq wPath (vl-filename-directory wPath)) (or (eq "\\" (substr wPath (strlen wPath))) (setq wPath (strcat wPath "\\"))) (setq ofile (open (strcat wPath fname) "w")) (foreach str '("demo : dialog { label = \"Select Function\"; spacer;" " : list_box { key = \"lst\"; } spacer; ok_cancel; }" ) (write-line str ofile)) (setq ofile (close ofile)) t) nil) t)) (defun Make_list (key lst) (start_list key) (mapcar (function add_list) lst) (end_list)) (cond ( (not (dcl_write "LMAC_demo.dcl")) (princ "\n** DCL could not be written **")) ( (<= (setq dc (load_dialog "LMAC_demo.dcl")) 0) (princ "\n** DCL File not Found **")) ( (not (new_dialog "demo" dc)) (princ "\** Dialog Could not be Loaded **")) (t (Make_list "lst" (mapcar (function car) data)) (setq ptr (set_tile "lst" "0")) (action_tile "lst" "(setq ptr $value)") (setq flag (start_dialog) dc (unload_dialog dc)) (if (= 1 flag) (eval (cdr (nth (atoi ptr) data)))))) (princ)) Quote
The Buzzard Posted April 8, 2010 Posted April 8, 2010 tagkelas, There you go, try Lee's method. Nice one Lee. Quote
Lee Mac Posted April 8, 2010 Posted April 8, 2010 Thanks Buzzard, It could be shortened further, but I like to perform more error checking to make sure that the dialog has been found and loaded. Quote
The Buzzard Posted April 8, 2010 Posted April 8, 2010 Thanks Buzzard, It could be shortened further, but I like to perform more error checking to make sure that the dialog has been found and loaded. The one I posted, I was going to use the method you showed me, But I kind of put that together in a rush. Quote
Lee Mac Posted April 8, 2010 Posted April 8, 2010 The one I posted, I was going to use the method you showed me, But I kind of put that together in a rush. No worries mate Quote
alanjt Posted April 8, 2010 Posted April 8, 2010 But I prefer this way (initget "1 2 3") (setq demo (getkword "\nSpecify demo number [1/2/3] <1>: ")) I would normally have a default as well. I was just offering a very basic one. Quote
tagkelas Posted April 8, 2010 Author Posted April 8, 2010 Thanks a lot Both methods are really good The Buzzard ((= FUNCT 0)(ALERT "You selected Demo 1")) (ALERT "You selected Demo 1") -> Is this the line where should I write the routine? Quote
The Buzzard Posted April 8, 2010 Posted April 8, 2010 Thanks a lotBoth methods are really good The Buzzard (ALERT "You selected Demo 1") -> Is this the line where should I write the routine? Yes, You can call out your function there. Example Local Functions (cond ((= FUNCT 0)(DEMO1)) ((= FUNCT 1)(DEMO2)) ((= FUNCT 2)(DEMO3))) or Global Functions (cond ((= FUNCT 0)(C:DEMO1)) ((= FUNCT 1)(C:DEMO2)) ((= FUNCT 2)(C:DEMO3))) Then it would go to its respected function. Local Functions (defun DEMO1 () (defun DEMO2 () (defun DEMO3 () or Global Functions (defun C:DEMO1 () (defun C:DEMO2 () (defun C:DEMO3 () Quote
tagkelas Posted April 8, 2010 Author Posted April 8, 2010 Thanks a lot In Lee Mac's method, how I change the label's "name"? (foreach str '("demo : dialog { label = \"Select Function\"; spacer;" " : list_box { key = \"lst\"; } spacer; ok_cancel; }" ) Select Function? Quote
The Buzzard Posted April 8, 2010 Posted April 8, 2010 Lee, I think he referring to the label called Select Function. It does not seem to change. Quote
tagkelas Posted April 8, 2010 Author Posted April 8, 2010 I mean this one: How do we change it? Quote
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.