Jump to content

List Box with 4 panes (list boxes) - Insert Action


Recommended Posts

Posted

Hey Guys,

I am trying to write a lisp that has 4 or 5 list boxes. "LS1" would be the main list that appears on the first pane. When you click on "General" then second list box then would contain "LS2" as a sub category on the second pane. Then, if for example "LDF" from the second list/ pane is selected, "LS3" would show up on third list box and hopefully upon double clicking, it would insert a block from "LS3" list. Hopefully someone can follow my logic here and provide some help as to how to go about it.

 

Thanks guys.

 

The original lisp in done by Lee Mac in 2015

https://www.theswamp.org/index.php?topic=49169.0

 

(defun c:CABLE ( / *error* dch dcl des idx ls1 ls2 ls3 ls4 )
 
    (defun *error* ( msg )
        (if (and (= 'int (type dch)) (< 0 dch))
            (unload_dialog dch)
        )
        (if (= 'file (type des))
            (close des)
        )
        (if (and (= 'str (type dcl)) (setq dcl (findfile dcl)))
            (vl-file-delete dcl)
        )
        (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )

(setq	ls1 (list "GENERAL" "BELL" "ROGERS" "VIDÉOTRON" "TELUS" "SUPPORT")
	ls2 (list "LDF" "AVA" "CNT" "AUTRE") ;; ls1 > "GENERAL"
        ls3 (list "LDF2-50A" "LDF4-50A" "LDF5-50A" "LDF6-50A" "LDF7-50A") ;; ls2 > "LDF"
	ls4 (list "AVA5-50A" "AVA6-50A" "AVA7-50A") ;; ls2 > "AVA"
	ls5 (list "CNT-300" "CNT-400") ;; ls2 > "CNT"
	ls6 (list "CAT5" "CABLE 2-0" "VXL7-50A" "RG6-FT1" "EWP132-144" "LMR-400") ;; ls2 > "AUTRE"
	ls7 (list "FO" "DC") ;; ls1 > "BELL"
	ls8 (list "FO" "DC") ;; ls1 > "ROGERS"
	ls9 (list "FO" "ALARME" "DC 2-CONDUCTEURS 4-AWG" "DC 12-CONDUCTEURS 8-AWG" "DC HYBRIDE 2-AWG"
		  "DC HYBRIDE 4-AWG" "DC HYBRIDE 6-AWG" "DC HYBRIDE 8-AWG") ;; ls1 > "VIDÉOTRON"
	ls10 (list "FO" "ALARME" "DC 2-CONDUCTEURS 8-AWG" "DC 6-CONDUCTEURS 8-AWG"
		  "DC 12-CONDUCTEURS 8-AWG" "DC 12-CONDUCTEURS 6x2x6-AWG") ;; ls1 > "TELUS"
	ls11 (list "LIST YET TO BE MADE") ;; ls1 > "SUPPORT"
	
); end setq

    (if
        (and
            (setq dcl (vl-filename-mktemp "tmp.dcl"))
            (setq des (open dcl "w"))
            (foreach str
               '(
                    "listbox : list_box"
                    "{"
                    "    width = 30;"
                    "    height = 40;"
                    "    fixed_width = true;"
                    "    fixed_height = true;"
                    "}"
                    "example : dialog"
                    "{"
                    "    label = \"CÂBLES ET LIGNES + SUPPORT DES CÂBLES\";"
                    "    spacer;"
                    "    : row"
                    "    {"
                    "        : listbox { key = \"ls1\"; }"
                    "        : listbox { key = \"ls2\"; }"
		    "        : listbox { key = \"ls3\"; }"
		    "        : listbox { key = \"ls4\"; }"
                    "    }"
                    "    ok_only;"
                    "}"
                )
                (write-line str des)
            )
            (not (setq des (close des)))
            (< 0 (setq dch (load_dialog dcl)))
            (new_dialog "example" dch)
        )
        (progn
            (fill_list "ls1" ls1)
           
;;;            (action_tile "ls1"
;;;                (vl-prin1-to-string
;;;                   '(if (= 4 $reason)
;;;                        (setq ls2 (fill_list "ls2" (append ls2 (list (nth (atoi $value) ls1))))
;;;                              ls1 (fill_list "ls1" (LM:removenth (atoi $value) ls1))
;;;                        )
;;;                    )
;;;                )
;;;            )
;;;            (action_tile "ls2"
;;;                (vl-prin1-to-string
;;;                   '(if (= 4 $reason)
;;;                        (setq ls1 (fill_list "ls1" (append ls1 (list (nth (atoi $value) ls2))))
;;;                              ls2 (fill_list "ls2" (LM:removenth (atoi $value) ls2))
;;;                        )
;;;                    )
;;;                )
;;;            )
            (if (and (= 1 (start_dialog)) ls2)
                (progn
                    (princ "\nThe user selected the following items:")
                    (foreach x ls2 (terpri) (princ x))
                )
                (princ "\n*Cancel*")
            )
        )
    )
    (*error* nil)
    (princ)
)
 
(defun fill_list ( key lst )
    (start_list key)
    (foreach itm lst (add_list itm))
    (end_list)
    lst
)
 
;; Remove Nth  -  Lee Mac
;; Removes the item at the nth index in a supplied list
 
(defun LM:removenth ( n l )
    (if (and l (< 0 n))
        (cons (car l) (LM:removenth (1- n) (cdr l)))
        (cdr l)
    )
)
 
(princ)

 

Posted
2 minutes ago, Steven P said:

If you look at Lee Macs website, I am sure he has an example somewhere to do something similar (http://www.lee-mac.com/),  (http://www.lee-mac.com/listboxsync.html)if this is what you are meaning?

 

No. What I am meaning is the method to embed one list into another so when a keyword is selected, it leads to another list and another selection.

If you run the lisp, you may get a bit more information - it is harder to explain in words than you trying it.

Posted
6 hours ago, Sambuddy said:

No. What I am meaning is the method to embed one list into another so when a keyword is selected, it leads to another list and another selection.

 

Like this?

Posted

@Lee Mac

Hey Lee,

I created the list boxes, thanks to your great work, and was wondering if I could have your help in inserting blocks based on the selection.

Example:  

C:CABLE 
The user selected: GENERAL, LDF, LDF2 - 50A

"LDF2 - 50A" to insert a block.

 

Could you please let me know what variable I should be choosing to make a condition and whether or not it should be within the first (if ...) ?

 

Thanks again

;; DCL List-Tile Dependency  -  V1.1 (2019-04-27)  -  Lee Mac
;; Configures action_tile statements for the list of keys to enabled dependency between the DCL tiles.
;; key     - [lst] List of DCL tile keys in order of dependency
;; lst-sym - [sym] Quoted variable containing list data
;; rtn-sym - [sym] Quoted variable containing initial selection indexes
(defun LM:dcld:action ( key lst-sym rtn-sym )
    
    (defun LM:dcld:addlist ( key lst )
        (start_list key)
        (foreach itm lst (add_list itm))
        (end_list)
    )
    (defun LM:dcld:getlists ( idx lst )
        (if (cdr idx)
            (cons (mapcar 'car lst) (LM:dcld:getlists (cdr idx) (cdr (nth (car idx) lst))))
            lst
        )
    )
    (defun LM:substnth ( itm idx lst )
        (if lst
            (if (zerop idx)
                (cons itm (mapcar '(lambda ( x ) 0) (cdr lst)))
                (cons (car lst) (LM:substnth itm (1- idx) (cdr lst)))
            )
        )
    )
    (defun LM:dcld:actions ( key lst-sym rtn-sym lvl / fun )
        (setq fun
            (if (cdr key)
                (list 'lambda '( val lst )
                    (list 'setq rtn-sym (list 'LM:substnth '(atoi val) lvl rtn-sym))
                    (list 'LM:dcld:addlist (cadr key) (list 'nth (1+ lvl) (list 'LM:dcld:getlists rtn-sym 'lst)))
                    (list
                        (LM:dcld:actions (cdr key) lst-sym rtn-sym (1+ lvl))
                        (list 'set_tile (cadr key) "0") 'lst
                    )
                )
                (list 'lambda '( val lst )
                    (list 'setq rtn-sym (list 'LM:substnth '(atoi val) lvl rtn-sym))
                )
            )
        )
        (action_tile (car key) (vl-prin1-to-string (list fun '$value lst-sym)))
        fun
    )
    (mapcar 'LM:dcld:addlist key (LM:dcld:getlists (eval rtn-sym) (eval lst-sym)))
    (   (eval (LM:dcld:actions key lst-sym rtn-sym 0))
        (set_tile (car key) (itoa (car (eval rtn-sym))))
        (eval lst-sym)
    )
    (princ)
)

;; DCL List-Tile Dependency  -  Get Items  -  Lee Mac
;; Returns a list of the items selected from each dependent list tile.
;; idx - [lst] List of selection indexes
;; lst - [lst] List data

(defun LM:dcld:getitems ( idx lst / tmp )
    (if (cdr idx)
        (cons (car (setq tmp (nth (car idx) lst))) (LM:dcld:getitems (cdr idx) (cdr tmp)))
        (list (nth (car idx) (car lst)))
    )
)

			

;; Two List Tile Dependency Example  -  Lee Mac
;; Requires ListTileDependency.lsp to be loaded.
(defun c:CABLE ( / *error* dch dcl des lst rtn )

    (defun *error* ( msg )
        (if (= 'file (type des))
            (close des)
        )
        (if (< 0 dch)
            (unload_dialog dch)
        )
        (if (and (= 'str (type dcl)) (findfile dcl))
            (vl-file-delete dcl)
        )
        (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )

(setq lst
'(
;;;("ITEM1"	("ITEM-1A"	("ITEM-1A1" "ITEM-1A2"))
;;;		("ITEM-1B"	("ITEM-1B1" "ITEM-1B2" "ITEM-1B3"))
;;;)
	 
("GENERAL"	("LDF"		("LDF2 - 50A" "LDF4 - 50A" "LDF5 - 50A" "LDF6 - 50A" "LDF7 - 50A"))
		("AVA"		("AVA5 - 50A" "AVA6 - 50A" "AVA7 - 50A"))
 		("CNT"		("CNT - 300" "CNT - 400"))
 		("AUTRE"	("CAT 5" "CABLE 2 - 0" "VXL7 - 50A" "RG6 - FT1" "EWP132 - 144" "LMR - 400"))
) ;END GENERAL

("BELL"		("FO"		("BELL FO"))
 		("DC"		("BELL DC"))
) ;END BELL

("ROGERS"	("FO"		("ROGERS FO"))
 	 	("DC"		("ROGERS DC"))
) ;END ROGERS

("VIDÉOTRON"	("FO"		("VIDÉOTRON FO"))
		("DC"		("DC 2 - CONDUCTEURS 4 - AWG" "DC 12 - CONDUCTEURS 8 - AWG" "DC HYBRIDE 2 - AWG""DC HYBRIDE 4 - AWG" "DC HYBRIDE 6 - AWG" "DC HYBRIDE 8 - AWG"))
 		("ALARME"	("VIDÉOTRON ALARME"))
) ;END VIDÉOTRON

("TELUS"	("FO"		("TELUS FO"))
		("DC"		("DC 2 - CONDUCTEURS 8 - AWG" "DC 6 - CONDUCTEURS 8 - AWG""DC 12 - CONDUCTEURS 8 - AWG" "DC 12 - CONDUCTEURS 6 x 2 x 6 - AWG"))
 		("ALARME"	("TELUS ALARME"))
) ;END TELUS

("SUPPORT"	("ITEM-A"		("ITEM - A1" "ITEM - A2"))
 	 	("ITEM-B"		("ITEM - B1" "ITEM - B2"))
) ;END SUPPORT
  
) ;END MASS PARAN
) ;END SETQ

	 


    (if
        (and
            (setq dcl (vl-filename-mktemp "tmp.dcl"))
            (setq des (open dcl "w"))
            (foreach str
               '(
                    "lbx : list_box"
                    "{"
                    "    alignment = centered;"
                    "    fixed_width = true;"
                    "    fixed_height = true;"
                    "    width = 35;"
                    "    height = 15;"
                    "}"
                    "test : dialog"
                    "{"
                    "    label = \"CÂBLES / LIGNES ET SUPPORT DES CÂBLES\";"
                    "    spacer;"
                    "    : row"
                    "    {"
                    "        : lbx { key = \"lb0\"; label = \"CATÉGORIE PRINCIPALE\"; }"
                    "        : lbx { key = \"lb1\"; label = \"SOUS-CATÉGORIE\"; }"
		    "        : lbx { key = \"lb2\"; label = \"BLOC\"; }"
                    "    }"
                    "    spacer;"
                    "    ok_cancel;"
                    "}"
                )
                (write-line str des)
            )
            (not (setq des (close des)))
            (< 0 (setq dch (load_dialog dcl)))
            (new_dialog "test" dch)
        )
        (progn           
            (setq rtn '(0 0 0))
            (LM:dcld:action '("lb0" "lb1" "lb2") 'lst 'rtn)
            (if (= 1 (start_dialog))
                (princ
                    (strcat "\nThe user selected:"
                        (substr
                            (apply 'strcat
                                (mapcar '(lambda ( x ) (strcat ", " x))
                                    (LM:dcld:getitems rtn lst)
                                )
                            )
                            2
                        )
                    )
                )
                (princ "\n*Cancel*")
            )
        ) 
    )
  
    (*error* nil)
    (princ)
); END DEFUN

 

Posted

No worries! I found my way!

(setq luckylist (LM:dcld:getitems rtn lst))
(setq luckylist (nth 2 luckylist))  
	(cond
		((= luckylist "LDF2 - 50A")(alert "LDF2 - 50A is Selected"))
		;the rest

Thanks

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...