See the top rated post in this thread. Click here

Results 1 to 6 of 6

Thread: Popup_list to Popup_list Control

  1. #1
    Member dhurd's Avatar
    Join Date
    2004-01
    Posts
    14
    Login to Give a bone
    0

    Question Popup_list to Popup_list Control

    I would like to have the user input from the first popup list control the available selections in the second list ie.
    popup1LIST: FRUIT, COLORS, CARS
    popup2LISTa: APPLES, ORANGES, PEARS
    popup2LISTb: RED, GREEN, BLUE
    popup2LISTc: VW, CHEVY, FORD

    I only want the selections of list "b" if the user picks "COLORS",etc.

    I've tried different types of "if" statements in the action_tile reaction area to no avail.

  2. #2
    100 Club
    Join Date
    2000-12
    Posts
    126
    Login to Give a bone
    2

    Default Re: Popup_list to Popup_list Control

    There are various techniques you can use. Guess the preferred method depends on which form you get the data and the kind of operations you need to perform.

    Unless other constructs are needed, I like to keep all the data in one place. For example, the data you describe could be gathered in a single list looking like this:

    (("FRUIT" ("APPLES" "ORANGES" "PEARS"))
    ("COLORS" ("RED" "GREEN" "BLUE"))
    ("CARS" ("VW" "CHEVY" "FORD")))

    When using the dcl list functions, one would simply add the CAR items to the popup_list and specify a callback that populates the list_box with whatever of the CAR items is chosen in the popup.

    For example:
    Code:
    // DCL definition
    
    myTest : dialog {
      label = "Test list controls";
      : list_box {
        key = "listbox";
        width = 20;
      }
      : popup_list {
        key = "popup";
        width = 20;
      }
      ok_only;
    }
    
    ;; LISP code
    
    (defun populate_list (tile item lst)
      (start_list tile)
      (mapcar 'add_list (cadr (nth item lst)))
      (end_list)
    )
    
    (defun listtest ()
      ;; set up data
      (setq myList '(("FRUIT"  ("APPLES" "ORANGES" "PEARS"))
                     ("COLORS" ("RED" "GREEN" "BLUE"))
                     ("CARS"   ("VW" "CHEVY" "FORD"))
                    )
      )
      
      (setq dcl_id (load_dialog "testdlg.dcl"))
      (cond ((new_dialog "myTest" dcl_id)
             
             ;; fill "popup" with CAR item of myList
             (start_list "popup")
             (mapcar 'add_list (mapcar 'car myList))
             (end_list)
             
             ;; fill "listbox" initially, according to default value of "popup"
             ;; (value of "0" unless otherwise specified in the dcl definition)
             (populate_list "listbox" 0 myList)
             
             ;; define callback to populate "listbox" according to
             ;; users choice in the "popup" tile
             (action_tile "popup" "(populate_list \"listbox\" (atoi $value) myList)")
    
             (start_dialog)
            )
      )
    )
    You will probably need to keep track of the chosen item(s) in the list_box. This could for be done by having the populate_list function return the sublist data plus setting the chosen item during callback from the list_box. Here's a simple example where the single choice is saved and returned (for single-selection list_box):

    Code:
    // DCL definition
    
    myTest : dialog {
      label = "Test list controls";
      : list_box {
        key = "listbox";
        width = 20;
      }
      : popup_list {
        key = "popup";
        width = 20;
      }
      : edit_box {
        key = "editbox";
        width = 20;
      }
      ok_only;
    }
    
    
    ;; LISP code
    
    (defun populate_list (tile item lst cleartiles / sublst)
      (start_list tile)
      (mapcar 'add_list (setq sublst (cadr (nth item lst))))
      (end_list)
      
      ;; clear any affected tiles
      (foreach n cleartiles
        (set_tile n "")
      )
      ;; return sublist
      sublst
    )
    
    (defun listtest ()
      ;; set up data
      (setq myList '(("FRUIT"  ("APPLES" "ORANGES" "PEARS"))
                     ("COLORS" ("RED" "GREEN" "BLUE"))
                     ("CARS"   ("VW" "CHEVY" "FORD"))
                    )
      )
      
      (setq dcl_id (load_dialog "testdlg.dcl"))
      (cond ((new_dialog "myTest" dcl_id)
             (setq item "")
             
             ;; fill "popup" with CAR item of myList
             (start_list "popup")
             (mapcar 'add_list (mapcar 'car myList))
             (end_list)
             
             ;; fill "listbox" according to default value of "popup" (value
             ;; of zero unless otherwise specified in the dcl definition)
             (setq subitems (populate_list "listbox" 0 myList '("editbox")))
             
             ;; define callback to populate "listbox" according to
             ;; users choice in the "popup" tile. Save list of items
             ;; in order to extract an item from the list_box tile
             ;; (also clear any choices in affected tiles when replacing list)
             (action_tile "popup" "(setq subitems (populate_list \"listbox\" (atoi $value) myList '(\"editbox\")))")
    
             ;; define callback to populate "editbox" and save current
             ;; choice in order to return it
             (action_tile "listbox" "(set_tile \"editbox\" (setq item (nth (atoi $value) subitems)))")
    
             (start_dialog)
             
             ;; report choice, if any
             (princ (strcat "You chose " (if (/= item "") item "nothing")))
            )
      )
      (princ)
    )

  3. #3
    Member dhurd's Avatar
    Join Date
    2004-01
    Posts
    14
    Login to Give a bone
    0

    Default Re: Popup_list to Popup_list Control

    Stig,

    Thanks for the help. I'm not sure if I want to persue the route you've listed as the depth of the list tree gets too complicated at the nth (about level. Your base code works well though and I'll most likely use it in annother app.

    TY
    Dave

  4. #4
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    0

    Default Re: Popup_list to Popup_list Control

    I don't see that it gets too complicated?
    Although you may want to restructure the list so they can be more dynamic & not redundant,
    Code:
    (setq Level1 (list 
                    '("REDFRUIT" 0) ; 0 points to element in next level
                    '("COLORS" 1)
                    '("CARS" 2)
                    '("FRAGRANCE" 0) ; reuse a list
                  )
     )
     (setq Level2 (list
                    (list
                      '("APPLES" 0) 
                      '("ORANGES" 1)
                      '("PEARS" 2)
                    )
                    (list
                      '("RED" 0) 
                      '("GREEN" 1)
                      '("BLUE" 2)
                    )
                    (list
                      '("VW" 0) 
                      '("CHEVY" 1)
                      '("FORD" 2)
                    )
                  )
     )
    ;;  levels could continue.
    ;; another pointer scheme could be ("APPLES" level3 0)
    ;; where 'level3' holds the list and 0 is the pointer

  5. #5
    Member
    Join Date
    2003-07
    Posts
    9
    Login to Give a bone
    0

    Default Re: Popup_list to Popup_list Control

    Hi,

    How do the same if I want get data from txt files. This is easier to change data without rewrite LISP and DCL code.

    Thank you

    Sérgio

  6. #6
    Member
    Join Date
    2014-11
    Posts
    21
    Login to Give a bone
    0

    Default Re: Popup_list to Popup_list Control

    What if I want each color in a different list box and just the size of the text

Similar Threads

  1. Style Based Control Versus Layer Based Control
    By FCahill in forum Civil 3D Styles Library
    Replies: 8
    Last Post: 2011-06-07, 04:56 PM
  2. How to Control the Use of...
    By CadDog in forum CAD Management - General
    Replies: 3
    Last Post: 2009-04-01, 07:35 PM
  3. Methods used to control drawing quality control?
    By tedg in forum CAD Management - General
    Replies: 20
    Last Post: 2006-08-02, 03:57 PM
  4. Sun Control
    By Alek Sutulov in forum Revit Architecture - General
    Replies: 3
    Last Post: 2004-01-06, 02:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •