Jump to content

Multi radio button selection


BIGAL

Recommended Posts

Hi Guys I read a post on another site and thought should be able to do this to have multiple radio buttons and pick multiple buttons. I understand radio buttons toggle. But I would have thought if they are in individual boxes in some way would react just that way individually. The idea was to take the library multi input and add multi buttons.

 

I have tried multi combos with not to much success at times button variable is changed but then not. The sample code will make a dcl just swap back to temp directory and un-remark delete file at end for testing looked at dcl to check bracket counts. The code should return RBx is 1 or 0

 

I am sure just overlooking something.

 

Any help would be appreciated.

 

See Below

 

 

Edited by BIGAL
Link to comment
Share on other sites

Think you will need toggles for this one Bigal. Radio buttons only make sense if there are at least 2 in a radio_row or a radio_column. Only way to accomplish what you want (if I understand it right) would be to make toggles aware of each other by what I call the toggle police. Call with each toggle action the same sub function where you can decide if toggle A = on ("1") , then toggle B and C must be switched off ("0")

  • Like 1
Link to comment
Share on other sites

Thanks guys will have another play. Using my multi getvals.lsp shrinking box size and put anything in a edit box does work was just trying to make picking easier. May look at greying edit box.

 

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq ans (AH:getvalsm (list "Tick items" "Blocks" 2 1 "" "Line" 2 1 "" "Circles" 2 1 "" "Plines" 2 1 "")))

 

image.png.bc8cd5cc44b92eea935ef9e0533d1b3c.png

Edited by BIGAL
Link to comment
Share on other sites

while back I was working on my batch app and wanted to be able to select just a few strings. Could of course use toggles but just for fun wanted to make something different. It is only ment for a short list with short strings

image.png.54d30bccbf7c0a31a1dcbca8f8949544.png

 


; multiple from list (setq inp (mfl '("A" "B" "C" "D") '("A" "B")))
(defun mfl (%l %df / toggle l f p d r)
  (setq l (mapcar '(lambda (x)(if (member x %df)(strcat "[X] " x)(strcat "[O] " x))) %l))
  (defun toggle (v / s r) (if (eq (substr (setq r (nth (atoi v) l)) 2 1) "X") (setq s "[O] ") (setq s "[X] "))
    (setq l (subst (strcat s (substr r 5)) r l))(start_list "lb")(mapcar 'add_list l)(end_list))
  (and (setq p (open (setq f (vl-filename-mktemp ".dcl")) "w"))
       (princ "cfl:dialog{label=\"Choose\";:list_box {key=\"lb\";} ok_cancel;}" p)
       (not (setq p (close p)))(< 0 (setq d (load_dialog f)))(new_dialog "cfl" d)
       (progn (start_list "lb")(mapcar 'add_list l)(end_list) (action_tile "lb" "(toggle $value)")
         (action_tile "accept" "(setq r (get_tile \"lb\"))(done_dialog 1)")
         (action_tile "cancel" "(setq r nil)(done_dialog 0)") (start_dialog)(unload_dialog d)(vl-file-delete f)))
  (mapcar '(lambda (y)(substr y 5)) (vl-remove-if '(lambda (x)(eq (substr x 2 1) "O")) l))
)

 

 

 

Link to comment
Share on other sites

Thanks rlx, I will probably go down the toggles path as the dcl can be done dynamically in terms of how many toggles.

 

This is the 3rd in the library series and can have as many toggles as required the selection is returned as a list.

 

Please feel free to use.

 

 

 

 

 

Multiple toggles.lsp

Edited by BIGAL
Link to comment
Share on other sites

 

@BIGAL toggle with checkbox output can be stored as bit is much convenient, like sysvar example (setvar 'osmode 24) etc.. 

 

(defun bits->fix ( l / e ans )   
(setq e 0 ans 0)
(repeat (length l )
(if (= (nth e (reverse l) ) 1 )
(setq ans (+ (expt 2 e) ans))
)
(setq e (1+ e))
   ans )
)

;(bits->fix  '(1 1 1 1 1 0 1 0 0 0)  )
1000

 

(setq ans (ah:toggs '("Choose a number" "1" "2" "3" "4" "5" "6" "7" "8" "9" "10")))

("1" "1" "0" "0" "1" "0" "0" "1" "1" "1")  ; long output

 

(setq toggs (bits->fix (mapcar 'atoi (reverse ans)) )
915

 

suggestion:

(mycheckbox strlst toggs) 

  • Like 1
Link to comment
Share on other sites

Not quite sure how I would use compared.

 

(if ( = (nth 1 ans) "1")(do something1))

(if ( = (nth 2 ans) "1")(do something2))

….

(if ( = (nth 9 ans) "1")(do something10))

 

This would allow 10 different options to be ran 1 after another. I should have posted original post request which is on another forum.

 

like a Audit then purge and purge again then saveas and close.

Edited by BIGAL
Link to comment
Share on other sites

Well had another go at a further library routine, why not a image as well as input boxes so describing what is required.

 

To run just edit last line so it can find the sld, you can try your own the siz makes the image bigger or smaller. Change list to your input. Normally run with out last line just use the if not to load as a library routine. example at top. Will look into vector image should improve quality

 

ps took 2 days to work out "Label" does not work must be lower case, such a simple mistake.

image.png.edbfeb5590ae2fa5d84e5a75c2c8080b.png

Multi GETVALS Img.lsp Furntable.sld

Edited by BIGAL
Link to comment
Share on other sites

On 23/10/2019 at 05:04, BIGAL said:

Not quite sure how I would use compared.

 

(if ( = (nth 1 ans) "1")(do something1))

(if ( = (nth 2 ans) "1")(do something2))

….

(if ( = (nth 9 ans) "1")(do something10))

 

This would allow 10 different options to be ran 1 after another. I should have posted original post request which is on another forum.

 

like a Audit then purge and purge again then saveas and close.

 

Using a slightly modified version of @hanhphuc code above (moved the return outside the loop) you could

 

(defun bits->fix ( lst / e ans )   
  (setq e 0 ans 0)
  (repeat (length lst)
    (if (= (nth e (reverse lst) ) 1)
      (setq ans (+ (expt 2 e) ans))
    );end_if
    (setq e (1+ e))
  );end_repeat
  ans
);end_defun

;Then process

(if (= (logand ans 1) 1)(do something1))
(if (= (logand ans 2) 2)(do something2))
(if (= (logand ans 4) 4)(do something3))
(if (= (logand ans 8) 8)(do something4))
(if (= (logand ans 16) 16)(do something5))
(if (= (logand ans 32) 32)(do something6))
(if (= (logand ans 64) 64)(do something7))
(if (= (logand ans 128) 128)(do something8))
(if (= (logand ans 256) 256)(do something9))
(if (= (logand ans 512) 512)(do something10))

 

Link to comment
Share on other sites

Understand now I think though for the more average lisp user the If = nth is easier to understand what is going on.

 

In a complex lisp using the single value is a good idea rather than the original post request which was about cleaning up a dwg and doing a sequence of steps.

Link to comment
Share on other sites

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...