Author Topic: HP:BUTTONS.lsp by - hanhphuc  (Read 1090 times)

0 Members and 1 Guest are viewing this topic.

milanp

  • Newt
  • Posts: 35
HP:BUTTONS.lsp by - hanhphuc
« on: February 18, 2023, 03:55:15 PM »
Is it possible to edit the code to allow multiple independent columns to be displayed?
I'll post a picture to describe what I mean

Code: [Select]
;|
Thank you for supporting this "HP:BUTTONS.lsp" DCL library.
This routine allows you to create DCL with multiple buttons associated to DCL action_tile list on the fly.
It creates DCL box with single column x nRows of buttons, 'n' depends on the length of the 'action list'
usage:
(hp:buttons title msg lst width ht)
title = Name caption on top of DCL - string
msg   = header or blank ""         - string
lst   = quoted list or progn list - list
width = Width of the dialod box - integer
ht    = height of each button - integer

returns nil or any execution (progn ... ) related to action_tile
Save this file into your support folder, append to your startup autoload routine.
In order to optimize the user experience, it allows maxinum 15 rows however you can abjust depends on screen size.

HP:BUTTONS - v1.0.1
Free LISP by - hanhphuc
email: hanhphuc.diy@outlook.com
|;


(defun hp:buttons ( title msg lst width ht / *error* dcl dd f fn ht i l wd)
 
  (defun *error* (msg) (if f (close f))(if fn (vl-file-delete fn)) )
 
  (if (and
(setq wd (* width 0.8)
      l (apply 'mapcar (cons 'list lst))
)
(< (length l) 15 ) ; <<--------------- 15 limited max Row ad just is you have bigger screen
(setq fn (vl-filename-mktemp nil nil ".dcl"))
(setq f (open fn "w"))
      )
    (progn
      (setq i 0)
      (foreach str
       (append
(list
   (strcat "dcl_button : dialog { label = \" "
    title
   " \"; width = "
   (rtos width 2 2)
   "; fixed_width = true;"
   )
   (strcat ": text { value = \"" msg "\"; alignment = left; }" )
   ": boxed_column { alignment = left ;children_alignment = left ;"
)
(mapcar
   '(lambda ($)
      (strcat
": button { label = \" "
$
" \"; key = \"key"
(itoa (setq i (1+ i)))
"\" ;width = "
(rtos wd 2 2)
"; fixed_width = true; height = "
(rtos ht 2 2)
"; fixed_height = true; alignment = centered; }"
      )
    )
   (car l)
)
(list
   "spacer_1; "
   "}"
   "ok_only ;}"    
)
       )
(write-line str f)
      )
      (close f)
    )
    (alert "Failed ! ")
  )
 
  (if (and (>= (setq dcl (load_dialog fn)) 0)
   (new_dialog "dcl_button" dcl)
      )

    (progn
      (setq i 0)
      (repeat (1+ (length lst))
(action_tile
  (strcat "key" (itoa (setq i (1+ i))))
  "(done_dialog (atoi (substr $key 4)))"
)
      )
     
     (action_tile
       "accept"
       "(done_dialog)"
     )
     
      (if (not (zerop (setq dd (start_dialog))))
(or
  (eval (nth (1- dd) (cadr l)))
  (done_dialog)
)
      )

      (unload_dialog dcl)
     
    )
   
    (unload_dialog dcl)
  )

  (if fn (vl-file-delete fn))
 
  (princ)
 
)

;;example :
(defun c:demo ( / lst )

;list format list must be quoted '((<text1> <Expression1>)(<text2> <Expression2 >) etc.. )
; <text> is caption on the button
(setq lst
'(("Test routine" (progn (alert "Test") (textscr)))
   ("Calculator" (startapp "CALC"))
   ("Control panel" (startapp "CONTROL"))
   ("Paint brush" (command "START" "PBRUSH"))
   ("Temp folder" (command "_START" (strcat (getvar 'tempprefix))))
   ("Options" (command "+OPTIONS" 6))
   ("Object snap" (command "+DSETTINGS" 2))
   ("Appload" (command "_APPLOAD"))
   ("VLISP" (C:VLIDE))
   ("Notepad" (startapp "NOTEPAD"))
   ("Excel" (command "_START" "EXCEL"))
   ("Google" (command "_BROWSER" "https://www.google.com"))
   ("DOS mode" (command "_START" "CMD"))
   ("Registry" (command "_START" "REGEDIT"))
   ("Help"
    (command
     "_BROWSER"
     "https://www.cadtutor.net/forum/forum/15-autolisp-visual-lisp-amp-dcl/"
    )
   )
  )
  )
 
;;supply parameters in the routine
(hp:buttons
  "Example apps" ;title
  "hanhphuc" ;header
  lst ;list
  20 ;dialog width
  1.5 ;button height
)
  (princ)
)

Thanks

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: HP:BUTTONS.lsp by - hanhphuc
« Reply #1 on: February 18, 2023, 10:21:14 PM »
This is not what you want but an example of 2 columns of radio buttons. I am looking at converting it to do as many as required, just work out how many sub lists that is loop number.

Code: [Select]
; Multi button Dialog box for 3 columns choice replacement of initget
; By Alan H OCT 2022 info@alanh.com.au

; It will remember what button was pressed if ran again with same request.

; just use "but" value and compare to a list
; (if (not ah:buttscol3)(load "Multi Radio buttons 3col.lsp"))
;(setq but1 1)
 ;(setq but2 1)
; (setq but3 1)
;(setq lst1 (list "Select number" "1" "2" "3" "4" "5" "6" "7" "8" "9" "10"))
;(setq lst2 (list "Select Char" "A" "B" "C" "D"))
 ;(setq lst3 (list "Select block " "A1" "B2" "C3" "D4"))
;(ah:buttscol3 but1 but2 but3 "Please choose" lst1 lst2 lst3 "H")

; (alert (strcat (nth but1 lst1) "\n" (nth but2 lst2) "\n" (nth but3 lst3)))

; The "V" implies column of  buttons "H" is rows
; if you want  a number use (atof (nth but butlst) or (atoi (nth but2 butlst2)


(defun col1 ( /  L)
(setq x 1)
(repeat (length butlst1)
    (setq L (strcat "1Rb" (rtos x 2 0)))
    (if  (= (get_tile L) "1" )
        (setq but1 x)
    )
    (setq x (+ x 1))
)
(princ)
)

(defun col2 (  / j)
    (setq x 1)
    (repeat (length butlst2)
        (setq j (strcat "2Rb" (rtos x 2 0)))
        (if  (= (get_tile j) "1" )
            (setq but2 x)
         )
        (setq x (+ x 1))
    )
(princ)
)

(defun col3 ( / k )
    (setq x 1)
    (repeat (length butlst3)
        (setq K (strcat "3Rb" (rtos x 2 0)))
        (if  (= (get_tile K) "1" )
            (setq but3 x)
         )
        (setq x (+ x 1))
    )
(princ)
)


(defun ah:buttscol3 (ahdef1 ahdef2  ahdef3 toplabel butlst1 butlst2 butlst3 verhor / fo fname x  k )
`
(setq len1 (length butlst1) len2 (length butlst2) len3 (length butlst3))

(setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w"))
(write-line  "AHbuttscol : dialog {" fo)
(write-line  (strcat " label = " (chr 34) toplabel (chr 34) ";" ) fo)
(if (= (strcase verhor) "V")
(write-line " : column {" fo)
(write-line " : row {" fo)
)
(write-line " : boxed_radio_column {" fo)
(write-line  (strcat " width = 24  ;")  fo)
(setq x 1)
(write-line  (strcat " label = " (chr 34) (nth 0 butlst1) (chr 34) " ;" )fo)
(repeat (- (length butlst1) 1)
    (write-line " : radio_button {" fo)
    (write-line  (strcat "key = "  (chr 34) "1Rb" (rtos  x  2 0)  (chr 34) ";") fo)
    (write-line  (strcat "label = " (chr 34) (nth x  butlst1) (chr 34) ";") fo)
    (write-line " }" fo)
    (write-line "spacer_1 ;" fo)
    (setq x (+ x 1))
)
(if (or (< len1 len2)(< len1 len3))
    (repeat (- len2 len1)
    (write-line "spacer_1 ;" fo)
    )
)
(write-line " }" fo)
(write-line " : boxed_radio_column {" fo)
(write-line  (strcat " width = 24 ;")  fo)
(setq x 1)
(write-line  (strcat " label = " (chr 34) (nth 0 butlst2) (chr 34) " ;" )fo)
(repeat (- (length butlst2) 1)
    (write-line " : radio_button {" fo)
    (write-line  (strcat "key = "  (chr 34) "2Rb" (rtos x  2 0)  (chr 34) ";") fo)
    (write-line  (strcat "label = " (chr 34) (nth x  butlst2) (chr 34) ";") fo)
    (write-line " }" fo)
    (write-line "spacer_1 ;" fo)
    (setq x (+ x 1))
)
(if (or (< len2 len1)(< len2 len3))
    (repeat  (- len1 len2)
        (write-line "spacer_1 ;" fo)
    )
)
(write-line " }" fo)
(write-line " : boxed_radio_column {" fo)
(write-line  (strcat " width = 24 ;")  fo)
(setq x 1)
(write-line  (strcat " label = " (chr 34) (nth 0 butlst3) (chr 34) " ;" )fo)
(repeat (- (length butlst3) 1)
    (write-line " : radio_button {" fo)
    (write-line  (strcat "key = "  (chr 34) "3Rb" (rtos x  2 0)  (chr 34) ";") fo)
    (write-line  (strcat "label = " (chr 34) (nth x  butlst3) (chr 34) ";") fo)
    (write-line " }" fo)
    (write-line "spacer_1 ;" fo)
    (setq x (+ x 1))
)
(if (or (< len3 len1)(< len3 len2))
    (repeat  (- len1 len2)
        (write-line "spacer_1 ;" fo)
    )
)
(write-line " }" fo)
(write-line " }" fo)
(write-line "spacer_1 ;" fo)
(write-line " ok_cancel ;" fo)
(write-line " }" fo)
(write-line " }" fo)
(close fo)


(setq dcl_id (load_dialog fname))
(if (not (new_dialog "AHbuttscol" dcl_id) )
    (exit)
)
(setq x 1)
(repeat (- (length butlst1) 1)
    (setq k (strcat "1Rb" (rtos x 2 0)))
    (action_tile k  (strcat "(setq but "  (rtos x 2 0) ")" ))
    (if (= ahdef1 x)(set_tile k "1"))
    (setq x (+ x 1))
)
(setq x 1)
(repeat (- (length butlst2)1)
    (setq k (strcat "2Rb" (rtos x 2 0)))
    (action_tile k  (strcat "(setq but2 "  (rtos x 2 0) ")" ))
    (if (= ahdef2 x)(set_tile k "1"))
    (setq x (+ x 1))
)
(setq x 1)
(repeat (- (length butlst3)1)
    (setq j (strcat "3Rb" (rtos x 2 0)))
    (action_tile j (strcat "(setq but3 "  (rtos x 2 0) ")" ))
    (if (= ahdef3 x)(set_tile j "1"))
    (setq x (+ x 1))
)
(action_tile "accept"  "(col1) (col2) (col3) (done_dialog)")
(action_tile "cancel" "(done_dialog) (exit)")
(start_dialog)
(unload_dialog dcl_id)
(vl-file-delete fname)

(princ)
) ; end defun ahbutscol3

A man who never made a mistake never made anything

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: HP:BUTTONS.lsp by - hanhphuc
« Reply #2 on: February 19, 2023, 06:36:10 PM »
did you contact email: hanhphuc.diy@outlook.com and ask for the change ?
A man who never made a mistake never made anything

maicy

  • Mosquito
  • Posts: 12
Re: HP:BUTTONS.lsp by - hanhphuc
« Reply #3 on: February 19, 2023, 10:07:25 PM »
(defun c:xxx ()
  (my_make_panel
    (list
      (list "梁"
            (list "画    梁" "circle") ;(list  按钮标签  运行的命令)
            (list "单线变梁" "mini_line_to_beam")
            (list "筏板梁倒角" "mini_foundation_beam")
            (list "修补梁柱" "mini_fix_beam")
            (list "修补双线" "mini_fix_dline")
            (list "框选修补线" "mini_fix_line")
      ) ;_ 结束list
      (list "柱"
            (list " + 型柱" "mini_c_column")
            (list " L 型柱" "mini_l_column")
            (list " T 型柱" "mini_t_column")
            (list " ○ 型柱" "mini_O_column")
            (list " □ 型柱" "mini_r_column")
            (list "轴线布柱" "mini_axis_column")
            (list "填 充 柱" "mini_fill_column")
            (list "墙体填充" "mini_fill_wall")
            (list "转PKPM GS柱" "mini_pline_to_beam")
            (list "多线变柱" "mini_pline_to_column")
      )
    )
  )
  (princ)
)


(defun my_make_panel ( menulist / n num_nobut num_button nn nnn menuname val_lst add_dclrow tt order_lst in num_image)
  (defun add_dclrow ( dstr / ) (if dstr (setq val_lst (cons dstr val_lst))))
  (setq menuname (strcat (vl-filename-mktemp) "temp_pannel.dcl"))
  (add_dclrow "curbutton:button{width=10;vertical_margin=none;vertical_margin=none;}")
  (add_dclrow "curimage:image{width=10;height=0.2;vertical_margin=none;vertical_margin=none;}")
  (add_dclrow "curpanel:dialog{label=\"My Command Panel\";alignment=centered;vertical_margin=none;horizontal_margin=none;")
  (add_dclrow ":row{")
  (setq len (apply 'max (mapcar 'length menulist))
        order_lst (apply 'append (mapcar 'cdr menulist))
        num_button 0
        num_nobut 0
        in 0
        num_image 0
  )
  (foreach nn menulist
        (setq in 0)
        (add_dclrow (strcat " : boxed_column{label=\"" (car nn) "\";vertical_margin=none; horizontal_margin=none;"))
        (foreach nnn (cdr nn)
           (setq num_button (1+ num_button)
                 in (1+ in)
                 num_image (1+ num_image)
                 tt (car nnn)
                 tt (if tt tt "")
           )
           (add_dclrow (strcat ":curbutton{label=\"" tt "\";key=\"but" (itoa num_button) "\";}"))
           (if (= 4 in)
               (progn (add_dclrow (strcat ":curimage{key=\"ima" (itoa num_image) "\";color=18;}"))
                      (setq in 0)
               )
           )
        )
        (repeat (- len (length nn))
           (setq num_nobut (1+ num_nobut)
                 in (1+ in)
                 num_image (1+ num_image)
           )
           (add_dclrow (strcat " : curbutton{key=\"butno" (itoa num_nobut) "\";color=-2;}"))
           (if (= 4 in)
               (progn (add_dclrow (strcat ":curimage{key=\"ima" (itoa num_image) "\";}"))
                      (setq in 0)
               )
           )
        )
        (add_dclrow "spacer;}")
  )
   (add_dclrow "}:button{label=\"Close\";key=\"cancel\";is_cancel=true;width=10;fixed_width=true;alignment=centered;}}")
   (vl-file-delete menuname)
   (setq nn (open menuname "w"))
   (foreach n (reverse val_lst) (write-line n nn))
   (close nn)
   (setq nnn (load_dialog menuname))
   (if (not (new_dialog "curpanel" nnn)) (exit))
   (setq n 0)
   (repeat num_nobut (mode_tile (strcat "butno" (itoa num_nobut)) 1) (setq num_nobut (1- num_nobut)))
  (foreach nn menulist
        (foreach nnn (cdr nn)
           (setq n (1+ n)
                 tt (car nnn)
                 tt (if tt tt "")
           )
           (if (= tt "")
               (mode_tile (strcat "but" (itoa n)) 1)
               (action_tile (strcat "but" (itoa n)) (strcat "\(done_dialog " (itoa n) "\)"))
           )
        )
  )
   (setq nn (start_dialog))
   (unload_dialog nnn)
   (vl-file-delete menuname)
  (if (> nn 0)
       (progn (setq tt (cadr (nth (1- nn) order_lst)))
              (princ "\n")
              (if (= (eval (read (strcat "(type c:" tt ")"))) 'SUBR)
                  (eval (read (strcat "(c:" tt ")")))
                  (vla-SendCommand(vla-get-ActiveDocument(vlax-get-acad-object))(strcat tt "\n"))
              )
       )
   )
)

maicy

  • Mosquito
  • Posts: 12
Re: HP:BUTTONS.lsp by - hanhphuc
« Reply #4 on: February 19, 2023, 10:16:35 PM »
  (if (> nn 0)
       (progn (setq tt (cadr (nth (1- nn) order_lst)))
              (princ "\n")
              (if (wcmatch (vl-string-trim " \t" tt) "\(*\)")
                  (eval (read (strcat "(progn " tt ")")))
                  (vla-SendCommand(vla-get-ActiveDocument(vlax-get-acad-object))(strcat tt "\n"))
              )
       )
   )

milanp

  • Newt
  • Posts: 35
Re: HP:BUTTONS.lsp by - hanhphuc
« Reply #5 on: February 20, 2023, 06:38:04 PM »
Thank you all for your time and suggestions. That's what I was looking for. You are the boss  :-)