Jump to content

Help with LeeMac lisp List-Tile Dependency


Recommended Posts

Posted (edited)

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 ;)
Posted (edited)

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
Posted
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!

Posted
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:

  • 4 months later...
Posted (edited)

Hello


Recently I discovered a problem in the lisp "ListTileDependencyV1-0.lsp" and "ListTileDependencyDemo.lsp"  (Lee MAc), during test2.

example:
if you select "Item 1, Item 1-a, Item 1-a-ii, Item 1-a-ii-1, Item 1-a-ii-1-c" and then return to your choice and you want select "Item 1-b" the lisp stops ...

 

I looked for a solution to this problem ... without success.

Do you have an idea to solve this error?

In advance, I thank you for it.

cordially

Dan

 

 

2.swf

Edited by bdan
Posted (edited)

@bdan

One way should be replacing the LM:substnth routine with:

  (defun LM:substnth (itm idx lst)
    (if lst
      (if (zerop idx)
        (cons itm (mapcar '(lambda (x) 0) (cdr lst)))
        (cons (car lst) (LM:substnth itm (1- idx) (cdr lst)))
      )
    )
  )

 

Edited by gile
  • Like 1
Posted (edited)

The solution to this issue ultimately depends on the appropriate course of action for updating the existing selections in the dependent list tiles when the user changes the selected item in a parent list tile. In the original code, I designed the function to attempt to retain as many of the existing selections in the dependent list tiles as possible, however, I overlooked the circumstance in which an entire branch of the dependency would be cut off by a change of selection in one of the parent list tiles, causing the nth expression in the LM:dcld:getlists function to fail.

 

A solution akin to the current logic would be to test whether each of the selection indices falls within a valid range for each list of items prior to or as part of evaluating the LM:dcld:getlists function, and revise the index to zero if it doesn't fall within such range. However, @gile's proposed solution is far more elegant and perhaps more intuitive and less likely to result in an unintended selection caused by the function attempting to retain a previous selection tree.

 

As such, I have updated the code as it appears on my site to incorporate @gile's suggestion (which also enabled me to remove a few other lines of code from the function which became redundant as a result of this change), with an appreciative nod to @gile included in the news section of my homepage.

Edited by Lee Mac
Posted

Thanks for compliment, Lee.

I'm not so great, it was easier to find a 'solution' to an issue reported by @bdan (here) than writing the original routine. ;)

Posted

Hello,

Thanks to Mac Lee and Gilles for the solution and also for the very interesting explanations!

Dan

Note: I think that the update of the page did not work. (links don't work correctly,        
ListTileDependencyV1-0.lsp   :   old lisp)
          http://lee-mac.com/listtiledependency.html

 

 

 

 


 

 

 

 

Posted
5 hours ago, bdan said:

Note: I think that the update of the page did not work. (links don't work correctly,         ListTileDependencyV1-0.lsp   :   old lisp)
          http://lee-mac.com/listtiledependency.html

 

 

 

 

It may be necessary to refresh the page (F5) to view the updated links, as your browser may have cached the old page.

Posted

Hello,

Thanks to Mac Lee and Gilles for the solution and also for the very interesting explanations!

Dan

Note: I think that the update of the page did not work. (links don't work correctly,        
ListTileDependencyV1-0.lsp   :   old lisp)
          http://lee-mac.com/listtiledependency.html

 

 

 

 

ok it's good

Thank you

 

 


 

 

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...