Two Dcl Dialog

Two Dcl Dialog

thabit79BL3
Enthusiast Enthusiast
1,173 Views
2 Replies
Message 1 of 3

Two Dcl Dialog

thabit79BL3
Enthusiast
Enthusiast

Dear AutoLisp Community,

 

I am writing to ask for your help as I am new to AutoLisp and still learning how to use it effectively. I have a question about whether it is possible to create two DCL files in AutoLisp that can interact with each other.

Specifically, I would like to create a first DCL file that asks the user for some information (such as X and Y coordinates), and then a second DCL file that uses this information to ask for more input (such as Z coordinate), after which the AutoLisp program should draw lines based on the information provided.

 

Ideally, I would like both DCL files to be included within the same Lisp file, for ease of use.

 

I am not sure if this is possible in AutoLisp, and would greatly appreciate any guidance or suggestions on how to achieve this functionality.

Thank you in advance for your help.

 

0 Likes
Accepted solutions (2)
1,174 Views
2 Replies
Replies (2)
Message 2 of 3

paullimapa
Mentor
Mentor
Accepted solution

Yes, it can be done.  Your lisp code can write a dcl on the fly to initially launch. Then after gathering information from that dialog, write on the fly another dcl file based on the info entered dismissing the current dialog and then launch the other. But the lisp will need to be coded so that the name of the second dcl file is predetermined this way it can specify the new_dialog function with the given dialog name. See if you can load & run this example I call Sample2.lsp.

Load & then launch Sample2 and then select an item on the list box. Then click Launch To 2nd DCL button. The current dialog is dismissed and a 2nd dialog appears with the Item info passed to it.

 

; SAMPLE2 function demonstrates launching another dcl on the fly
(defun C:SAMPLE2 (/ aec_TmpDir dcl_id ddiag do_wrt_dcl do_wrt_dcl2 myItem myList myList0 myList2 mySelection) ; local variables

; do_wrt_dcl function writes DCL file on the fly
(defun do_wrt_dcl (name / fp)
  (if (and name (setq fp (open name "w")))
    (mapcar 
      '(lambda (x)(write-line x fp))
       (list
         "SAMPLE1 : dialog {"
         "  label = \"Sample - List, Edit && Text Boxes\";"
         "  : column {"
         "      : list_box {"
         "        label = \"&Choose Item\";"
         "        key = \"myList\";"
         "        height = 15;"
         "        width = 25;"
         "         multiple_select = false;"
         "//        multiple_select = true;"
         "        fixed_width_font = true;"
         "        value = \"\";"
         "       }"
         "       "
         "       : edit_box {"
         "         label = \"&Edit Box\";"
         "         key = \"myEdit\";"
         "//         height = 1;"
         "//         width = 25;"
         "         fixed_width_font = true;"
         "         value = \"\";"
         "       }"
         "       : boxed_row {"              
         "         label = \"Text Box\";"              
         "         mnemonic = \"T\";"              
         "         alignment = left;"              
         "         : text {"              
         "            label = \"This is Text\";"              
         "            key = \"myText\";"              
         "            width = 10;"              
         "//           fixed_width = true;"              
         "            alignment = top;"              
         "         }"              
         "       }"              
         "      : button {"
         "        key = \"launch\";"
         "        label = \"Launch To 2nd DCL\";"
         "      }"
         
         "    : boxed_row {"
         "      : button {"
         "        key = \"accept\";"
         "        label = \"Okay\";"
         "        is_default = true;"
         "      }"
         "      "
         "      : button {"
         "        key = \"cancel\";"
         "        label = \"cancel\";"
         "        is_default = false;"
         "        is_cancel = true;"
         "      }"
         "    }"
         "  }"
         "}"
      )
    )
  )
  (if fp (close fp))
 ) ; defun do_wrt_dcl
 
; do_wrt_dcl2 function writes DCL file on the fly
(defun do_wrt_dcl2 (name / fp)
  (if (and name (setq fp (open name "w")))
    (mapcar 
      '(lambda (x)(write-line x fp))
       (list
         "SAMPLE2 : dialog {"
         "  label = \"Sample - Another DCL\";"
         "         : text {"              
         "            label = \"This is 2nd DCL\";"              
         "            key = \"myText\";"              
         "            width = 40;"              
         "//           fixed_width = true;"              
         "            alignment = top;"              
         "         }"              
         
         "    : boxed_row {"
         "      : button {"
         "        key = \"accept\";"
         "        label = \"Okay\";"
         "        is_default = true;"
         "      }"
         "      "
         "      : button {"
         "        key = \"cancel\";"
         "        label = \"cancel\";"
         "        is_default = false;"
         "        is_cancel = true;"
         "      }"
         "    }"
         "}"
      )
    )
  )
  (if fp (close fp))
 ) ; defun do_wrt_dcl2
; create list
 (setq myList0 (list (cons "Item0" "12")(cons "Item1" "24")(cons "Item2" "36")(cons "Item3" "48")) ; create assoc pair list
       myList (mapcar '(lambda (x) (car x)) myList0) ; creat list of just first item in assoc pair for list box
 )

; setup temp folder
  (setq aec_TmpDir (strcat (getenv"Temp")"\\"))  ; acad temp folder location
; write dcl on the fly
 (do_wrt_dcl (strcat aec_TmpDir "SAMPLE1.dcl"))

 ;;;---Load the dcl file from disk into memory
 (if (not (setq dcl_id (load_dialog (strcat aec_TmpDir "SAMPLE1.dcl")))) ; load dcl written on the fly
  (progn
   (alert "SAMPLE1.dcl file could not be loaded!")
   (exit)
  )

  ;;;---Else, the DCL file was loaded
  (progn
   ;;;---Load the dialog definition inside the DCL file
   (if (not (new_dialog "SAMPLE1" dcl_id))
    (progn
     (alert "The SAMPLE1.dcl file could not be loaded!")
     (exit)
    )
    ;;;---Else, the definition was loaded
    (progn
     ;;;--- populate list box
     (start_list "myList" 3) 
     (mapcar 'add_list myList)
     (end_list)

     ;;;--- set default list box selection
     (setq myItem "0") ; set item index
     (setq mySelection (nth (atoi myItem) myList)) ; get value per item index
     (set_tile "myList" myItem) ; highlight item index on list box
     (set_tile "myEdit" mySelection)  ; place value from list to edit box
     (set_tile "myText" (cdr(assoc mySelection myList0))) ; place assoc pair value onto text box

     ;;;---if an action event occurs, do these functions
     ;;;---place list box selected item into edit box
     (action_tile "myList" 
      "(setq mySelection (set_tile \"myEdit\" (nth (atoi (setq myItem $value)) myList)))
       (set_tile \"myText\" (cdr (assoc mySelection myList0))) 
       "
     ) 
     ;;;---check item entered in edit box if match to list box
     (action_tile "myEdit" 
      "(if(member $value myList)
        (progn (set_tile \"myList\" (setq myItem (itoa(- (length myList) (length (member $value myList))))))
               (set_tile \"myText\"  (cdr (assoc (nth (atoi myItem) myList) myList0)))
        ) 
         (progn (alert\"No Matching Items...Will Set back to Previous Value\")(set_tile \"myEdit\" mySelection))
       )"
     )
      (action_tile "launch" "(setq mySelection (nth (atoi(get_tile \"myList\")) myList))(done_dialog 3)")
      (action_tile "accept" "(setq mySelection (nth (atoi(get_tile \"myList\")) myList))(setq myItem (get_tile \"myText\"))(done_dialog 2)")
      (action_tile "cancel" "(done_dialog 1)") 

     ;;;---Display the dialog box
     (setq ddiag (start_dialog))

    ;;;---Unload the dialog box
    (unload_dialog dcl_id)

    ;;;--- empty dialog box contents
    (close(open(strcat aec_TmpDir "SAMPLE1.dcl")"w"))

    ;;;---if the user pressed the Cancel button
    (if (= ddiag 1)
     (princ "\nSAMPLE1 cancelled!")
    )

    ;;;---if the user pressed the Okay button
    (if (= ddiag 2)
      ;;;---Inform the user of his selection from the first list
      (princ (strcat"\nYour choice(s) from the list box is: " mySelection "\nYour choice from the text box is: " myItem))
    ); if

    ;;;---if the user pressed the Launch button
    (if (= ddiag 3)
      (progn
      ; write dcl on the fly
       (do_wrt_dcl2 (strcat aec_TmpDir "SAMPLE2.dcl"))
;;;---Load the dcl file from disk into memory
 (if (not (setq dcl_id (load_dialog (strcat aec_TmpDir "SAMPLE2.dcl")))) ; load dcl written on the fly
  (progn
   (alert "SAMPLE2.dcl file could not be loaded!")
   (exit)
  )

  ;;;---Else, the DCL file was loaded
  (progn
   ;;;---Load the dialog definition inside the DCL file
   (if (not (new_dialog "SAMPLE2" dcl_id))
    (progn
     (alert "The SAMPLE2.dcl file could not be loaded!")
     (exit)
    )
    ;;;---Else, the definition was loaded
    (progn
      (set_tile"myText"(strcat"Your Choice From Previous DCL was: [" mySelection "]"))

      (action_tile "accept" "(done_dialog 2)")
      (action_tile "cancel" "(done_dialog 1)") 

     ;;;---Display the dialog box
     (setq ddiag (start_dialog))

    ;;;---Unload the dialog box
    (unload_dialog dcl_id)

    ;;;--- empty dialog box contents
    (close(open(strcat aec_TmpDir "SAMPLE2.dcl")"w"))

    ;;;---if the user pressed the Cancel button
    (if (= ddiag 1)
     (princ "\nSAMPLE2 cancelled!")
    )

    ;;;---if the user pressed the Okay button
    (if (= ddiag 2)
     (princ "\nSAMPLE2 OK button Clicked!")
    ); if

    ) ; progn
   ); if

    ) ; progn
   ); if
    ;;;;---Suppress the last echo for a clean exit
    (princ)
        
      ) ; progn
    ); if

    ;;;;---Suppress the last echo for a clean exit
    (princ)

    ); progn
   ); if
  ); progn
 ); if
  
 (princ) ; clean exit
); C:SAMPLE2

 

paulli_apa_0-1676952263904.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 3

Sea-Haven
Mentor
Mentor
Accepted solution

You can have child DCL.

SeaHaven_0-1676952474652.png

 

Note the wall dcl is interactive displaying total width using either value input or the sliders which are set to 10mm increments. Use a slider total changes.