DCL default value

DCL default value

ВeekeeCZ
Consultant Consultant
556 Views
6 Replies
Message 1 of 7

DCL default value

ВeekeeCZ
Consultant
Consultant

Quick question guys,

 

It's a sort of general DCL sub originally made by Ronjonp... can't figure out what to add to accept the first line by default by hitting Enter (if multiple_select is allowed)

 

Load - Enter returns nil, I want '("0") for the following test func

 

eekeeCZ_0-1732015645215.png

 

 

thx

 

 

 

 

 

(defun c:test ()

    (defun :DclList (title lst multi / ch flg tmp file id lst)
     ;; based of ronjonp's code
    (if (and (setq tmp (vl-filename-mktemp nil nil ".dcl"))
	     (setq file (open tmp "w"))
	     (write-line (strcat "Dcllist : dialog { initial_focus = \"l\"; label = \"" title
				 "\";spacer;: row {: list_box {key = \"l\"; alignment = centered; width = "
				 (itoa (min (+ 10 (car (vl-sort (mapcar 'strlen (mapcar 'vl-princ-to-string lst)) '>))) (fix (/ (car (getvar 'screensize)) 10))))
				 "; height = " (itoa (min (+ 3 (length lst)) (fix (/ (cadr (getvar 'screensize)) 12))))
				 ";" (if multi " multiple_select = true;" " multiple_select
				 = false;") " allow_accept = true;"
				 "}}spacer;ok_cancel;}")
	       file)
	     (not (close file)))
      (progn
	(setq id (load_dialog tmp))
	(new_dialog "Dcllist" id)
	(start_list "l")
	(mapcar 'add_list (mapcar '(lambda (x) (vl-princ-to-string x)) lst)) (end_list)
	(set_tile "l" "0") ; to highlight initial row
	(action_tile "l" "(setq ch $value)")
	(setq flg (start_dialog))
	(unload_dialog id)
	(vl-file-delete tmp)
	(if (and ch (= 1 flg))
	  (mapcar '(lambda (x) (nth x lst)) (read (strcat "(" ch ")")))))))


  (:DclList "title" '("0" "1" "2" "3") t))

 

 

 

 

 

0 Likes
Accepted solutions (1)
557 Views
6 Replies
Replies (6)
Message 2 of 7

komondormrex
Mentor
Mentor

gave exactly ("0") multiple times in a row. 2024.

0 Likes
Message 3 of 7

ВeekeeCZ
Consultant
Consultant

I've fixed the test line to T (as for multiple mode)

 

I get "0" just for a simple mode, nil for multiple. Run the code, hit enter right away.

Even tried to restart my 2024, still the same result.

 

Thanks for testing..

0 Likes
Message 4 of 7

komondormrex
Mentor
Mentor
Accepted solution

add

(setq ch "0")

after line 21, cause when you just hit enter ch is always nil.

Message 5 of 7

ВeekeeCZ
Consultant
Consultant

Thank you

0 Likes
Message 6 of 7

scot-65
Advisor
Advisor

The following is a generalized outline of how to structure a program that uses a dialog where the dialog will remember and populate the last user selection the next time the dialog is called forward. This also demonstrates the ability to catch errors before closing the dialog.

 

Create an initialization section in your code after the "new_dialog" line.

Before is also acceptable in some situations.

Other sections as shown (this is how my template looks).

This example demonstrates the session gremlin method of data storage.

 

(new_dialog ...)

;** Initialize **

(or USER_MyProg (setq USER_MyProg "1"))

 

;** Set Tile **

Populate the list box here.

Set the list box here with USER_MyProg:

(set_tile "Lis01" USER_MyProg)

 

;** Mode Tile **

(mode_tile "accept" 2) ;set focus to the accept button if the list box allow_accept is disabled in the DCL.

 

;** Action Tile **

Send to a sub-function:

(action_tile "accept" "(if (MyProg_GET (get_tile \"Lis01\")) (done_dialog 1))")

(start_dialog)

 

(defun MyProg_GET (a/)

In this sub function, perform a gauntlet [COND] to check valid values (especially list boxes) as needed.

If this does not pass the gauntlet, issue an alert and return nil. The dialog will remain open.

(alert "Invalid entry for List Box.") nil

If everything passes:

(setq USER_MyProg a)

);end MyProg_GET

 

Exit the dialog and use USER_MyProg to fetch the data and process.

USER_MyProg is not limited to one value.

I frequently use it as a LIST. --> (set_tile "xxx" (nth 0 USER_MyProg))...

 

Hope this helps.

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 7 of 7

ВeekeeCZ
Consultant
Consultant

@scot-65 

 

thank you for your explanation.

I work with DCL very rarely, so I'm not that versed in them. Any minor issue is very time-consuming to crack.

0 Likes