Author Topic: need some help with - DCL list dependency - listbox synchronisation  (Read 3857 times)

0 Members and 1 Guest are viewing this topic.

DraxJDM

  • Newt
  • Posts: 47
hey all,

i try to build on 2 examples from Lee Mac.

for the first, DCL list tile dependency. i changed the DCL with a extra list (no dependecy) and a free text field.
the dcl part i think is oké, but i cannot get the extra fields to work :-(
to test also load the listtiledependency file from Lee's site
Code: [Select]
;;  List Tile Dependency Example  -  Lee Mac
;; Requires ListTileDependency.lsp to be loaded.

(defun c:test1_a1 ( / *error* dch dcl des lst rtn )

 ;;; end subroutine

    (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
   '(
     ("German"   
   ("Audi"    ("TTS Quattro" "TT RS" "S3 Quattro" "S4 Quattro" ))
   ("BMW"     ("M3" "M5" "M6" "X5" "Z3" "Z4"))
   ("Porsche" ("911" "924" "928" "930" "944" "Boxster" "Cayenne" "Cayman"))
   
      )
     ("English"     
     ("Jaguar"  ("XF" "XJ6" "XJR" "XKR" "X-Type" "S-Type"))
     ("Bentley"  ("Cintinental" "Flying Spur" "Mulliner" "Bentayga" ))
     
      )   
    )
  )



  ;; list colr
  (setq lst-Color (list "Blue" "Red"))


    (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 = 20;"
                    "    height = 15;"
                    "}"
;;
    "ebx : edit_box"
    "{"
    "    fixed_width = true;"
     ;; key = "Edit1";//Edit1$ from lsp file
                    "    width = 20;"
                    "}"
;;
                    "test : dialog"
                    "{"
                    "    label = \"List Box Dependency Example\";"
                    "    spacer;"
                    "    : row"
                    "    {"
    "        : lbx { key = \"lb1\"; label = \"List Box 1\"; }"
    "        : ebx { key = \"ebx2\"; label = \"text box 2\"; }"
                    "        : lbx { key = \"lb3\"; label = \"List Box 3\"; }"
                    "        : lbx { key = \"lb4\"; label = \"List Box 4\"; }"
    "        : lbx { key = \"lb5\"; label = \"List Box 5\"; }"
                    "    }"
                    "    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 '("lb3" "lb4" "lb5") 'lst 'rtn)
  ;; how do i add the lst-Color
  ;; and how the textbox :-(
          ;;

;;;  ; Set Default Variables
;;;  (setq NewText$ Edit1$)
;;;
;;;  ; Set Dialog Initial Settings
;;;  (set_tile "ebx2" Edit1$)
;;;  ; Dialog Actions
;;;  (setq NewText$ (get_tile \"ebx2\""))

  ;;
            (if (= 1 (start_dialog))
      (setq return (LM:dcld:getitems rtn lst))
                (princ "\n*Cancel*")
            )
        )
    )
    (*error* nil)
    (princ)
)


link to lee's source: http://www.lee-mac.com/listtiledependency.html


for the second, where i try to extend from 2 lists tot 3 lists. the last listbox is not updated with the right list.
this can also be done with the tile dependency, but i try to see how it can work with separated lists.
Code: [Select]
(defun c:listboxexample_a-b ( / *error* UpdateList data dclfile dclhandle )

  ;; This program demonstrates how to update a secondary list_box based
  ;; on user selection from a primary list_box.

  ;; Example courtesy of Lee Mac © 2010 (www.lee-mac.com)

  ;; Accompanying DCL File:
  ;; ddcl file location : C:\Users\FDC018\OneDrive - ENGIE\__Lisp\__load_Files

  (setq dclFile "listboxexampleAA.dcl")
 
  ;; Ensure this file resides in an AutoCAD Support Path

  (defun *error* ( msg )

    ;; Error Handler - will unload the dialog
    ;; from memory should the user decide to hit Esc

    (if dclHandle (unload_dialog dclHandle))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ)
  )

  (defun UpdateList ( key lst )

    ;; This function updates the list_box associated with the specified key
    ;; using the contents of the supplied lst

    (start_list key)
    (mapcar 'add_list lst)
    (end_list)
  )

  ;; Data used to Populate List_Boxes:
  ;; I've chosen to use this list structure because it suits the data,
  ;; but there are many other possibilities.
  (setq Data1
   '(
     ("German"    ("Audi" "BMW" "Porsche"))
     ("English"     ("Jaguar" "Bentley"))   
    )
  )

  (setq Data2
   '(
     ("Audi"    ("TTS Quattro" "TT RS" "S3 Quattro" "S4 Quattro" "S5 Quattro" "RS5 Quattro" "RS6 Quattro"))
     ("BMW"     ("M3" "M5" "M6" "X5" "Z3" "Z4"))
     ("Porsche" ("911" "924" "928" "930" "944" "Boxster" "Cayenne" "Cayman"))
    )
  )
 
  (setq Data3
   '(
     ("Jaguar"  ("XF" "XJ6" "XJR" "XKR" "X-Type" "S-Type"))
     ("Bentley"  ("Cintinental" "Flying Spur" "Mulliner" "Bentayga" ))
    )
  )

  ;; Start of Main Routine
  ;; Lots of Error Trapping to make sure the Dialog Loads:

  (cond
    ( (<= (setq dclHandle (load_dialog dclFile)) 0)

      (princ "\n--> DCL File not Found.")
    )
    ( (not (new_dialog "listboxexampleAA" dclHandle))

      (setq dclHandle (unload_dialog dclHandle))
      (princ "\n--> Dialog Definition not Found.")
    )
    ( t
      ;; Dialog Loaded Successfully.

      ;; Set up some default selections, for the first-time running of the program.
      ;; The variables *Make* & *Model* are intended to be global and hence will
      ;; remember the user's last selections.
      (or *Country*  (setq *Country*  "0"))
      (or *Make*  (setq *Make*  "0"))
      (or *Model* (setq *Model* "0"))

      ;; Populate the List_Boxes:
     
      ;; List_Box 'lst2'
     
      (UpdateList "lst2" (mapcar 'car Data1))
      (set_tile "lst2" *Country*)

      ;; List_Box 'lst4'
     
      (UpdateList "lst4" (cadr (nth (atoi *Country*) Data1)))
      (set_tile "lst4" *Make*)

      ;; List_Box 'lst5'

      ;(UpdateList "lst5" (cadr (nth (atoi *Make*) Data2)))
     ;(if (member *make* data2) (setq data-x data2) (setq data-x data3))
     (UpdateList "lst5" (cadr (nth (atoi *Make*) Data-x)))
      (set_tile "lst5" *Model*)

      ;; Action_tile Statements:
      ;; These control what happens when the user interacts with a tile in the dialog.
     (action_tile "lst2"
        (strcat
          "(UpdateList \"lst4\" (setq lst4 (cadr (nth (atoi (setq *Country* $value)) Data1))))"
          "(setq *Make*"
          "  (set_tile \"lst4\""
          "    (if (< (atoi *Make*) (length lst4)) *Make* \"0\")"
          "  )"
          ")"
        )
      )
     
      ;; Here, when the user selects an item from 'lst4', the UpdateList subfunction
      ;; is fired to update the items in list_box 'lst5'.

      ;; list_box 'lst5' is also set to the value of *Model* if the index is
      ;; available for the selected item, else the first item is selected.

      ;; Note that $value is a string containg the index of the item
      ;; that the user has selected. (setq $value 1)
      (action_tile "lst4"
        (strcat
  ;"(if (member (car (nth  (setq *Make* $value) Data-x)) data2) (setq data-x data2) (setq data-x data3))"
          "(UpdateList \"lst5\" (setq lst5 (cadr (nth (atoi (setq *Make* $value)) Data-x))))"
          "(setq *Model*"
          "  (set_tile \"lst5\""
          "    (if (< (atoi *Model*) (length lst5)) *Model* \"0\")"
          "  )"
          ")"
        )
      )



      ;; list_box 'lst5' is also set to the value of *Model* if the index is
      ;; available for the selected item, else the first item is selected.

      ;; Note that $value is a string containg the index of the item
      ;; that the user has selected.

      (action_tile "lst5" "(setq *Model* $value)")

      ;; Dialog setup, lets start it:

      (start_dialog)
      (setq dclHandle (unload_dialog dclHandle))
    )
  )
  (princ)
)

and dcl file
Code: [Select]
// DCL File to be saved as listboxexample.dcl
// Example courtesy of Lee Mac © 2010 (www.lee-mac.com)

lbox : list_box { width = 25; fixed_width = true; alignment = centered; }

listboxexampleAA : dialog { label ="List Box Synchronisation"; spacer;
  : row {
    : lbox { key = "lst2"; label = "Country"; }
    : lbox { key = "lst4"; label = "Make" ; }
    : lbox { key = "lst5"; label = "Model"; }
  }
  ok_only;
}


link to lee's source:http://www.lee-mac.com/listboxsync.html


Tottaly stuck on this, also just starting with DCL.
So a little explanation on what i am missing or doing wrong is helpful.

Thx John

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: need some help with - DCL list dependency - listbox synchronisation
« Reply #1 on: November 21, 2020, 11:38:04 AM »
For the first example, you'll need to populate list box lb1 with the items in your list lst-Color using the start_list, add_list, and end_list functions; you'll then need to define an appropriate action_tile statement to capture the user's selection, or alternatively call the get_tile function prior to the user dismissing the dialog.

Though, if you are only just starting with DCL, it may be easier to learn the basics from a tutorial such as this prior to configuring more advanced controls such as dependent list boxes.

DraxJDM

  • Newt
  • Posts: 47
Re: need some help with - DCL list dependency - listbox synchronisation
« Reply #2 on: November 25, 2020, 02:43:28 PM »
i will look at afra lisp to see if i can figure it out. :-)

i start with this because it fit what i need now 

DraxJDM

  • Newt
  • Posts: 47
Re: need some help with - DCL list dependency - listbox synchronisation
« Reply #3 on: December 02, 2020, 08:26:39 AM »
Lee,

I found a solution on the site you recommended.
thank you for guiding me.