guitarguy1685 Posted December 4, 2009 Posted December 4, 2009 Hello guys, I've been learning some DCL recently. I bought some books, read some online stuff. I making the dialog boxes seems pretty easy, my big problem is with writing LISP to make it work. My Dialog box is attached below. What I would like to happen is when I select an item in the fist popup_list box a list will be available in the 2nd. That list will depend on the first popup_list box selection. Likewise, a list will be displayed in the 3rd popup_list box. that list will depend on what was selected in the 2nd pop up box. Finally when I press the insert button it will insert the item in the 3rd popup_list Is this possible to do? I am also attaching my DCL and LSP file. InsP.DCLFetching info... InsP.LSPFetching info... Quote
MSasu Posted December 4, 2009 Posted December 4, 2009 This may help you solve your first issue: ;routine to fill values from a list to a pop-up list tile (defun FillPopUpList( theTile theList / ) (start_list theTile) ;start pop-up tile fill operation (mapcar 'add_list theList) ;load items from list to pop-up tile (end_list) ) ;routine to fill a pop-up list tile based on selection on another (defun ActionOnMy1stList( / theUserSelection ) (setq theUserSelection (get_tile "My1stList")) ;read which entry user selected ;fill second pop-up list with a content related to current selection in first one (cond ((= theUserSelection "1") (FillPopUpList "My2ndList" '("a" "b" "c"))) ((= theUserSelection "2") (FillPopUpList "My2ndList" '("A" "B" "C"))) ((= theUserSelection "3") (FillPopUpList "My2ndList" '("X" "Y" "Z"))) ) ) (FillPopUpList "My1stList" '("1" "2" "3")) ;prepare first pop-up list (action_tile "My1stList" "(ActionOnMy1stList)") ;define associated action on pop-up tile Remember that each action of a tile should be provided as a string. Quote
MSasu Posted December 4, 2009 Posted December 4, 2009 Second issue: to get the selection from third pop-up tile, take care of the fact that the tile will return the index of selected item as string: (setq The3rdSelection (nth (atoi (get_tile "My3rdList")) the3rdListContent)) where the the3rdListContent variable store the list curently loaded in the tile. Quote
guitarguy1685 Posted December 4, 2009 Author Posted December 4, 2009 wow you are a smart man. I really do appreciate it. Now just give me time to try to understand it. again thanks! Quote
Lee Mac Posted December 4, 2009 Posted December 4, 2009 Msasu - no need for get_tile, just use $value :wink: Quote
Lee Mac Posted December 4, 2009 Posted December 4, 2009 Another way: (defun mk_lst (key lst) (start_list key) (mapcar 'add_list lst) (end_list)) (defun get_lst (key code) (cond ( (eq key "lvl1") (cond ( (eq code 0) '("A" "B" "C" "D")) ( (eq code 1) '("E" "F" "G" "H")))) ( (eq key "lvl2") (cond ( (eq code 0) '("I" "J" "K" "L")) ( (eq code 1) '("M" "N" "O" "P")))))) (action_tile "lvl1" (vl-prin1-to-string (quote (progn (mk_lst "lvl2" (get_lst "lvl1" $value)))))) (action_tile "lvl2" (vl-prin1-to-string (quote (progn (mk_lst "lvl2" (get_lst "lvl2" $value)))))) Quote
guitarguy1685 Posted December 8, 2009 Author Posted December 8, 2009 Does this look like i'm on the right path? I abbreviated some of the variables ;;;;AUTOLISP CODING STARTS HERE (prompt "\nType InsP123 to run.....") ;;;command line prompt. FYI only (defun C:InsP123 () ;;;;no local variables at the moment ;;;--- Load the WSI Part DCL file (setq dcl_id (load_dialog "InsP123.dcl")) ;;;---Load the dialog Definition if it is not already loaded (if (not (new_dialog "InsP123" dcl_id)) (exit ) );;;close if statment ;routine to fill values from a list to a pop-up list tile (defun FillPopUpList( theTile theList / ) (start_list theTile) ;start pop-up tile fill operation (mapcar 'add_list theList) ;load items from list to pop-up tile (end_list) ) ;;;routine to fill a pop-up list tile based on selection on another (defun ActL1( / theUserSelection ) ;;;ActL1 is Action on List #1 (setq US1 (get_tile "lvl1")) ;;;read which entry user selected. US1 is User Selection for pop_up lst #1 ;;;fill second pop-up list with a content related to current selection in first one (cond ((= US1 "1") (FillPopUpList "lvl2" '("[select Part Type]" "2.1A" "2.1B" "2.1C"))) ((= US1 "2") (FillPopUpList "lvl2" '("[select Part Type]" "2.2A" "2.2B" "2.2C"))) ((= US1 "3") (FillPopUpList "lvl2" '("[select Part Type]" "2.3A" "2.3B" "2.3C"))) ((= US1 "4") (FillPopUplist "lvl2" '("[select Part Type]" "2.4A" "2.4B" "2.4c"))) ((= US1 "5") (FillPopUplist "lvl2" '("[select Part type]" "2.5A" "2.5B" "2.5C"))) ) ;;;close condition ) ;;;close ActionOnMy1stList function (defun ActL2 ( / S2) (setq US2 (get_tile "lvl2")) ;;;hopefully read user entry on 2nd box ;;;;fill 3rd pop_up list with content (cond ((= US2 "1") (FillPopUpList "lvl3" '("[select Part Size]" "3.1A" "3.1B" "3.1C"))) ((= US2 "2") (FillPopUpList "lvl3" '("[select Part Size]" "3.2A" "3.2B" "3.2C"))) ((= US2 "3") (FillPopUpList "lvl3" '("[select Part Size]" "3.3A" "3.3B" "3.3C"))) ((= US2 "4") (FillPopUpList "lvl3" '("[select Part Size]" "3.4A" "3.4B" "3.4C"))) ((= US2 "5") (FillPopUpList "lvl3" '("[select Part Size]" "3.4A" "3.4B" "3.5C"))) ) ) (defun ActL3 ( / S3) (setq US3 (get_tile "lvl3")) (cond ((= US3 "1") (FillPopUpList "lvl4" '("[select Part Size]" "4.1A" "4.1B" "4.1C"))) ((= US3 "2") (FillPopUpList "lvl4" '("[select Part Size]" "4.2A" "4.2B" "4.2C"))) ((= US3 "3") (FillPopUpList "lvl4" '("[select Part Size]" "4.3A" "4.3B" "4.3C"))) ((= US3 "4") (FillPopUpList "lvl4" '("[select Part Size]" "4.4A" "4.4B" "4.4C"))) ((= US3 "5") (FillPopUpList "lvl4" '("[select Part Size]" "4.4A" "4.4B" "4.5C"))) ) ) (FillPopUpList "lvl1" '("[select Name]" "A-Part" "B-Part" "F-Part" "G-Part" "H-Part")) ;prepare first pop-up list (action_tile "lvl1" "(ActL1)") ;define associated action on pop-up tile (action_tile "lvl2" "(ActL2)") (action_tile "lvl3" "(ActL3)") (action_tile "insert" "(done_dialog)" );;; close action_tile (start_dialog) (unload_dialog dcl_id) (princ) );;;; close defun (princ) ;;;;AUTOLISP CODING ENDS HERE So far the only prob I got was if after selecting the 4th box, if I go back and change the option in box 1 the others will not reset. Quote
MSasu Posted December 8, 2009 Posted December 8, 2009 The lists were reset – the only issue is that there isn’t a default selection after that. In order to get an entry in a pop-up list selected after the tile is filled will need to call set_tile with the index of desired entry (as string): (set_tile "lvl#" "0") The same, when re-set the second list is a better idea to clear the third-one since his content is obsolete – just call start_list/end_list without fill: (defun ActL1( / theUserSelection ) ;;;ActL1 is Action on List #1 (setq US1 (get_tile "lvl1")) ;;;read which entry user selected. US1 is User Selection for pop_up lst #1 ;;;fill second pop-up list with a content related to current selection in first one (cond ((= US1 "1") (FillPopUpList "lvl2" '("[select Part Type]" "2.1A" "2.1B" "2.1C"))) ((= US1 "2") (FillPopUpList "lvl2" '("[select Part Type]" "2.2A" "2.2B" "2.2C"))) ((= US1 "3") (FillPopUpList "lvl2" '("[select Part Type]" "2.3A" "2.3B" "2.3C"))) ((= US1 "4") (FillPopUplist "lvl2" '("[select Part Type]" "2.4A" "2.4B" "2.4c"))) ((= US1 "5") (FillPopUplist "lvl2" '("[select Part type]" "2.5A" "2.5B" "2.5C"))) ) ;;;close condition [color=red] (set_tile "lvl2" "0")[/color] [color=red] (foreach TempTile '("lvl3" "lvl4") (start_list TempTile) (end_list))[/color] ) ;;;close ActionOnMy1stList function Quote
MSasu Posted December 8, 2009 Posted December 8, 2009 Another recommendation is to use arguments for done_dialog action – use 1 for OK (Insert in your case) and 0 for Cancel: (action_tile "accept" "(done_dialog 1)") (action_tile "cancel" "(done_dialog 0)") This value will be store in "DIASTAT" system variable; use it to test the way used to end the dialog and act accordingly: continue processing or exit routine. Quote
guitarguy1685 Posted December 11, 2009 Author Posted December 11, 2009 SO msasu, where did you learn to LISP? books, classes or trial and error? I mean you use functions that I can't even find in AutoCAD help topics. Quote
Lee Mac Posted December 11, 2009 Posted December 11, 2009 msasu said: This value will be store in "DIASTAT" system variable; use it to test the way used to end the dialog and act accordingly: continue processing or exit routine. It is also returned by (start_dialog). 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.