Jump to content
ziele_o2k

Help with LeeMac lisp List-Tile Dependency

Recommended Posts

ziele_o2k

I know lisp but I don't handle very well with Run-time Evaluation and quoted stuff like Lee

Could someone help me to modify this LeeMac lisp in way that after double click there will be some function evaluated?

;; DCL List-Tile Dependency  -  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 (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 / tmp )
                    (list 'setq  rtn-sym  (list 'LM:substnth '(atoi val) lvl rtn-sym)
                                'tmp      (list 'LM:dcld:getlists rtn-sym 'lst)
                    )
                    (list 'LM:dcld:addlist (cadr key) (list 'nth (1+ lvl) 'tmp))
                    (list 'if (list '<= (list 'length (list 'nth (1+ lvl) 'tmp)) (list 'nth (1+ lvl) rtn-sym))
                        (list 'setq rtn-sym (list 'LM:substnth 0 (1+ lvl) rtn-sym))
                    )
                    (list
                        (LM:dcld:actions (cdr key) lst-sym rtn-sym (1+ lvl))
                        (list 'set_tile (cadr key) (list 'itoa (list 'nth (1+ lvl) rtn-sym))) '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)))
    )
)

 

Edited by ziele_o2k
Added headers in LeeMac's code to fulfill terms of use his code ;)

Share this post


Link to post
Share on other sites
ziele_o2k
50 minutes ago, Lee Mac said:


Forgive me @Lee Mac, I forgot to add link.

Edited by ziele_o2k

Share this post


Link to post
Share on other sites
Grrr

Better to investigate Lee's demo functions - include allow_accept attribute for the list_box, and enable it to true.

Then perform a test-condition on (LM:dcld:getitems rtn lst), that returned the DCL input and execute your function.

 


Another approach (that would violate Lee's terms of use) would be to 
replace the:

(action_tile (car key) (vl-prin1-to-string (list fun '$value lst-sym)))

with:

(setq myfun
  '(lambda  nil
    (alert (strcat "Hello there,\nkey" (apply 'strcat (mapcar 'vl-prin1-to-string (list $key '- $value))) "\nwas pressed"))
  )
)
(action_tile (car key) 
  (strcat 
    "(progn"
    "(if (= $reason 4)"
    "("
    (vl-prin1-to-string myfun)
    ")"
    ")"
    (vl-prin1-to-string
      (list fun '$value lst-sym)
    )
    ")"
  )
)

located within the LM:dcld:actions subfunction
 

The difference between the 1st and 2nd approach is that in the first the dialog will be closed and then your function will be executed, while in the 2nd the dialog will remain opened.

 

Edited by Grrr

Share this post


Link to post
Share on other sites
ziele_o2k
6 hours ago, Grrr said:

Better to investigate Lee's demo functions - include allow_accept attribute for the list_box, and enable it to true.

 Then perform a test-condition on (LM:dcld:getitems rtn lst), that returned the DCL input and execute your function.

Ok that was my solution, I didn't know that if I will add  allow_accept in DCL and acction_tile "accept" in my list, this will work :)

So simply... Thanks a lot @Grrr!

Share this post


Link to post
Share on other sites
Grrr
13 minutes ago, ziele_o2k said:

Ok that was my solution, I didn't know that if I will add  allow_accept in DCL and acction_tile "accept" in my list, this will work :)

So simply... Thanks a lot @Grrr!

 

No problem,

In a nutshell if you set the allow_accept = true; in a list_box, that would mean that whatever item you double-click on the dialog will close, similarly to assigning the action like this:

(foreach key ListBoxKeys
  (action_tile key 
    "(if (= 4 $reason)"
    "(done_dialog 1)"
    TheActionFunctionUserWanted
    ")"
  )
)

And one important note -

If you intend to run your function and then restore the dialog,

then don't neglect the rtn symbol (in Lee's demo), because you could use it to restore the last chosen values as default when redisplaying it.

(setq rtn '(0 0))
(LM:dcld:action '("lb0" "lb1") 'lst 'rtn)
(cond 
  ( (eq rtn (2 3)) (MyFunction) )
  ( (LM:dcld:action '("lb0" "lb1") 'lst 'rtn) ) ; the dialog will redisplay with the last stored values(indexes) in 'rtn
)

Honestly I wasn't aware that Lee would take care of that already, so I was about to write some constructive-criticism.

But the brilliancy of his work talks for itself..

:beer:

Share this post


Link to post
Share on other sites
Lee Mac

Thank you Grrr 👍

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×