Author Topic: Help optimize the function  (Read 1737 times)

0 Members and 1 Guest are viewing this topic.

77077

  • Guest
Help optimize the function
« on: September 16, 2015, 09:56:23 AM »
Dear guys

Help optimize the function, Thanks a lot.

Code - Auto/Visual Lisp: [Select]
  1. ;;(editlst '(("tag1" . "val1") ("tag2" . "val2") ("tag3" . "val3") ("tag4" . "val4")))
  2. (defun editlst (lst / fname fn i dclid lst_tag lst_val len_txt len_edbox)  
  3.         (setq lst_tag(mapcar 'car lst))
  4.         (setq lst_val(mapcar 'cdr lst))
  5.         (setq len_txt(+(apply 'max (mapcar 'strlen lst_tag))2))
  6.         (setq len_edbox(+(apply 'max (mapcar 'strlen lst_val))2))
  7.         (setq fname (vl-filename-mktemp nil nil ".dcl"))
  8.         (setq fn (open fname "w"))
  9.         (write-line "EditDCL:dialog{label=\"Attribute block Editor\";" fn)
  10.         (write-line ":boxed_row { " fn)
  11.         (write-line ":column {" fn)
  12.         (foreach n lst_tag
  13.                 (write-line
  14.                         (strcat ": text { label=\"" n "\";
  15.                                 width ="(itoa (fix len_txt))"; fixed_width = true;}"
  16.                         )
  17.                         fn
  18.                 )
  19.         )
  20.         (write-line "}" fn)
  21.         (write-line ":column {" fn);;
  22.         (setq i 1)
  23.         (foreach n lst_val
  24.                 (write-line
  25.                         (strcat ": edit_box {value=\"" n "\";
  26.                                 key=\"key" (itoa i) "\";
  27.                                 width ="(itoa (fix len_edbox))"; fixed_width = true;}"
  28.                         )
  29.                         fn
  30.                 )
  31.                 (setq i (1+ i))
  32.         )
  33.         (write-line "}\n}" fn)
  34.         (write-line "ok_cancel;" fn)
  35.         (write-line "}" fn)
  36.         (close fn)
  37.         (setq dclid (load_dialog fname))
  38.         (vl-file-delete fname)
  39.         (new_dialog "EditDCL" dclid)
  40.         (action_tile "accept" "(done_dialog 1)")
  41.         (action_tile "cancel" "(done_dialog 0)")
  42.         (start_dialog)
  43.         (unload_dialog dclid)
  44. )
  45.  
  46.  


This is not perfect . if more Attribute (>= 20), The Dialog will very long.
I hope one column =10 , if attribute >10 , need Add a column ...
if necessary, use the "spacer" controls to filling




« Last Edit: September 16, 2015, 11:53:12 AM by JAY »

77077

  • Guest
Re: Help optimize the function
« Reply #1 on: September 16, 2015, 08:05:37 PM »
Waiting. please give some good ideas. Thanks

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Help optimize the function
« Reply #2 on: September 17, 2015, 04:40:13 AM »
I  don't understand why you want to create your own attribute editor instead of using the built-in editor.
But, having said that, there are two things that I would change in your solution:
  • I would nest each text (= pseudo label) and edit_box in a separate row to ensure proper vertical alignment.
  • I would use a fixed dcl file and limit the number of attributes in the dialog to 10 and use Next and Previous buttons to page through the attributes.
Of course your function is still incomplete. My guess is that you want to return a new list in a format similar to the input.

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: Help optimize the function
« Reply #3 on: September 17, 2015, 05:04:49 AM »

77077

  • Guest
Re: Help optimize the function
« Reply #4 on: September 17, 2015, 06:10:17 AM »
I  don't understand why you want to create your own attribute editor instead of using the built-in editor.
But, having said that, there are two things that I would change in your solution:

I can use command "attedit" for attribute edit. My purpose is to learning methods .

Quote
  • I would nest each text (= pseudo label) and edit_box in a separate row to ensure proper vertical alignment.
  • I would use a fixed dcl file and limit the number of attributes in the dialog to 10 and use Next and Previous buttons to page through the attributes.
Of course your function is still incomplete. My guess is that you want to return a new list in a format similar to the input.
You mean like this ?
Code: [Select]
(strcat ": row { : text { label=\"" (car n) "\";}
                 : edit_box {value=\"" (cdr n) "\";key=\"key" (itoa I) "\"; width = 5; fixed_width = true;}}"
      )

This is my old function.
Code - Auto/Visual Lisp: [Select]
  1. (defun editlst (lst / getdata fname fn i lst1 dclid)  
  2.         (defun getdata()
  3.                 (setq lst1 nil i 1)
  4.                 (foreach n lst
  5.                         (setq lst1 (cons (cons (car n) (get_tile (strcat "key" (itoa i)))) lst1)
  6.                                 i (1+ i)
  7.                         )
  8.                 )
  9.         )
  10.         (setq fname (vl-filename-mktemp nil nil ".dcl"))
  11.         (setq fn (open fname "w"))
  12.         (write-line "EditDCL:dialog{label=\"Attribute block Editor\";" fn)
  13.         (write-line ":boxed_column{ " fn)
  14.         (write-line ":row{\n:column{" fn)
  15.         (setq I 1)
  16.         (foreach n lst
  17.                 (write-line
  18.                         (strcat ":edit_box{label=\"" (car n)
  19.                                 "\";value=\"" (cdr n)
  20.                                 "\";key=\"KEY" (itoa I) "\";}"
  21.                         )
  22.                         fn
  23.                 )
  24.                 (if (= (rem i 10) 0) (write-line "}\n:column{" fn))
  25.                 (setq I (1+ I))
  26.         )
  27.         (if (/= (rem (1- i) 10) 0) (write-line "}" fn))
  28.         (write-line "}\n}" fn)
  29.         (write-line "ok_cancel;" fn)
  30.         (write-line "}" fn)
  31.         (close fn)
  32.         (setq dclid (load_dialog fname))
  33.         (vl-file-delete fname)
  34.         (new_dialog "EditDCL" dclid)
  35.         (action_tile "accept" "(getdata)(done_dialog 1)")
  36.         (action_tile "cancel" "(done_dialog 0)")
  37.         (start_dialog)
  38.         (unload_dialog dclid)
  39.         (if lst1
  40.                 (setq lst (reverse lst1))
  41.                 (setq lst lst)
  42.         )
  43. )
  44.  

Thank for your idea.  Roy.

77077

  • Guest
Re: Help optimize the function
« Reply #5 on: September 17, 2015, 06:11:43 AM »
This old program may give you some ideas:
http://www.theswamp.org/index.php?topic=49266.msg543703#msg543703

Lee,Thanks ,I will have a look and study.