TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: kruuger on September 04, 2012, 07:11:32 AM

Title: Any way to improve coding ?
Post by: kruuger on September 04, 2012, 07:11:32 AM
hello,

please see attached code and image below.
is there any better way to improve coding for this dialog ?
especially for action_tile "IMx", function _UpdateImageButton and variable *im *or *by.

is code a little bit clear for you, how all things work together or definitely need rework ?

thank you
kruuger
Title: Re: Any way to improve coding ?
Post by: ElpanovEvgeniy on September 04, 2012, 08:03:11 AM
usually, I wrap this code in 'foreach

Code - Auto/Visual Lisp: [Select]
  1.       (action_tile "IM1" "(setq *im (cd:LST_ReplaceItem 0 *im (abs (- 1 (nth 0 *im)))) *or (abs (- 1 (nth 0 *im))) *by 0) (_UpdateImageButton)")
  2.       (action_tile "IM2" "(setq *im (cd:LST_ReplaceItem 2 *im (abs (- 1 (nth 2 *im)))) *or (abs (- 1 (nth 2 *im))) *by 1) (_UpdateImageButton)")
  3.       (action_tile "IM3" "(setq *im (cd:LST_ReplaceItem 4 *im (abs (- 1 (nth 4 *im)))) *or (abs (- 1 (nth 4 *im))) *by 2) (_UpdateImageButton)")
Title: Re: Any way to improve coding ?
Post by: kruuger on September 04, 2012, 08:41:15 AM
thanks Evgeniy

it seems that it should work but error ?
Code - Auto/Visual Lisp: [Select]
  1.       (foreach % (list 0 1 2)
  2.         (action_tile (strcat "IM" (itoa (1+ %)))
  3.           (vl-prin1-to-string
  4.             (quote
  5.               (progn
  6.                 (setq *im (cd:LST_ReplaceItem (* 2 %) *im (abs (- 1 (nth (* 2 %) *im))))
  7.                       *or (abs (- 1 (nth (* 2 %) *im)))
  8.                       *by %
  9.                 )
  10.                 (_UpdateImageButton)
  11.               )
  12.             )
  13.           )
  14.         )
  15.       )

kruuger
Title: Re: Any way to improve coding ?
Post by: Lee Mac on September 04, 2012, 09:13:57 AM
The symbol '%' won't be evaluated inside the quoted expression.
Title: Re: Any way to improve coding ?
Post by: kruuger on September 05, 2012, 05:22:28 PM
thanks Lee. is there any way to fix this or need to play with strcat
Code - Auto/Visual Lisp: [Select]
  1.       (foreach % (list 0 1 2)
  2.         (action_tile (strcat "IM" (itoa (1+ %)))
  3.           (strcat
  4.             "(setq *im (cd:LST_ReplaceItem (* 2 " (itoa %) ") *im (abs (- 1 (nth (* 2 " (itoa %) ") *im))))"
  5.             "      *or (abs (- 1 (nth (* 2 " (itoa %) ") *im)))"
  6.             "      *by " (itoa %) ")"
  7.             "(_UpdateImageButton)"
  8.           )
  9.         )
  10.       )
kruuger
Title: Re: Any way to improve coding ?
Post by: Lee Mac on September 05, 2012, 07:09:21 PM
Maybe not better, but find attached my thoughts on a different way to code it.  :-)
Title: Re: Any way to improve coding ?
Post by: kruuger on September 06, 2012, 03:43:36 PM
Maybe not better, but find attached my thoughts on a different way to code it.  :-)
thanks Lee. it is good to see the different approach  :-)

kruuger
Title: Re: Any way to improve coding ?
Post by: Lee Mac on September 06, 2012, 06:42:09 PM
You're welcome kruuger, hope it helps  :-)