JuniorNogueira Posted February 25, 2019 Posted February 25, 2019 What's the best way to make the <A> value equal to my last choice? Example: I called the command test I chose "B" when I reconnect the value of "B" is in my enter. any suggestions on how to improve the code? (defun c:TEST (/ pos) (and (not (initget "A B C D")) (setq pos (getkword "\nChoice[A/B/C/D] <A>: ")) ) (if (findfile (strcat "c:\\Teste\\" pos ".dwg")) (command "_.Insert" (strcat "c:\\Teste\\" pos ".dwg") "_Scale" 1 pause "" "_.Explode" (entlast)) ) (princ) ) Thanks in advance Quote
ronjonp Posted February 25, 2019 Posted February 25, 2019 (edited) (defun c:test (/ pos) ;; Save variable to the registry .. good across sessions (or (setq pos (getenv "MySavedSetting")) (setq pos "A")) (cond ((and (not (initget "A B C D")) (setq pos (getkword (strcat "\nChoice[A/B/C/D] <" pos ">: "))) (findfile (strcat "c:\\Teste\\" pos ".dwg")) ) (command "_.Insert" (strcat "c:\\Teste\\" pos ".dwg") "_Scale" 1 pause "" "_.Explode" (entlast) ) (setenv "MySavedSetting" pos) ) ) (princ) ) (defun c:test nil ;; Or use global .. good for current session (or pos (setq pos "A")) (if (and (not (initget "A B C D")) (setq pos (getkword (strcat "\nChoice[A/B/C/D] <" pos ">: "))) (findfile (strcat "c:\\Teste\\" pos ".dwg")) ) (command "_.Insert" (strcat "c:\\Teste\\" pos ".dwg") "_Scale" 1 pause "" "_.Explode" (entlast)) ) (princ) ) Edited February 25, 2019 by ronjonp 1 Quote
JuniorNogueira Posted February 25, 2019 Author Posted February 25, 2019 @ronjonp Thank you very much. but how to enter ENTER ? Quote
ronjonp Posted February 25, 2019 Posted February 25, 2019 7 minutes ago, JuniorNogueira said: @ronjonp Thank you very much. but how to enter ENTER ? Wrap your getkword in something like this: (setq pos (cond ((getkword (strcat "\nChoice[A/B/C/D] <" pos ">: "))) (pos) ) ) 1 Quote
Lee Mac Posted February 25, 2019 Posted February 25, 2019 (edited) Here's a tutorial describing various ways to achieve this - I believe you're interested in what I refer to as the "Dynamic Default". Edited February 25, 2019 by Lee Mac 1 Quote
Grrr Posted February 25, 2019 Posted February 25, 2019 47 minutes ago, Lee Mac said: Here's a tutorial describing various ways to achieve this - I believe you're interested in what I refer to as the "Dynamic Default". Actually you did one more - self redefining function, but it seems too complex for your "Prompting with a Default Option" tutorial. 1 Quote
BIGAL Posted February 26, 2019 Posted February 26, 2019 (edited) I have gone away from initget to using dcl's with radio buttons. It would make sense to highlight the button that has been previously picked so you just pick OK. This code needs that added Grrr you out there ? ; Multi button Dialog box for a single choice replacement of initget ; By Alan H Feb 2019 ; Example code ; (setq butlst '("A B or C " "A" "B" "C" ) ) ; (if (not AH:Butts)(load "Radio buttons multi.lsp")) ; (setq ans (ah:butts "V" butlst)) ; ans holds the button picked value ; (setq butlst '("Yes or No" "Yes" "No")) ; (if (not AH:Butts)(load "Radio buttons multi.lsp")) ; (setq ans (ah:butts "h" butlst)) ; ans holds the button picked value (vl-load-com) (defun AH:Butts (verhor butlst / fo fname x k ) (setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w")) (write-line "AHbutts : dialog {" fo) (write-line (strcat " label =" (chr 34) (nth 0 butlst) (chr 34) " ;" )fo) (write-line " : row {" fo) (if (= (strcase verhor) "V") (write-line " : boxed_radio_column {" fo) (write-line " : boxed_radio_row {" fo) ) (setq x 1) (repeat (- (length butlst) 1) (write-line " : radio_button {" fo) (write-line (strcat "key = " (chr 34) "Rb" (rtos x 2 0) (chr 34) ";") fo) (write-line (strcat "label = " (chr 34) (nth x butlst) (chr 34) ";") fo) (write-line " }" fo) (setq x (+ x 1)) ) (write-line " }" fo) (write-line " }" fo) (write-line " ok_only;" fo) (write-line " }" fo) (close fo) (setq dcl_id (load_dialog fname)) (if (not (new_dialog "AHbutts" dcl_id) ) (exit) ) (setq x 1) (repeat (- (length butlst) 1) (setq k (strcat "Rb" (rtos x 2 0))) (action_tile k (strcat "(setq but " (rtos x 2 0) ")" "(done_dialog)")) (setq x (+ x 1)) ) (start_dialog) (unload_dialog dcl_id) (vl-file-delete fname) ; which one picked (nth but butlst) ) ; these 2 lines are the calling code in a seperate lisp program (if (not Ah:Butts4)(load "Radio buttons multi")) (setq pos (AH:Butts4 "V" "Choose A B C D" "A" "B" "C" "D")) ; check val1 val2 val3 val4 for = "1" this is picked button. Edited February 28, 2019 by BIGAL 1 Quote
JuniorNogueira Posted February 27, 2019 Author Posted February 27, 2019 Very very much thank you guys !! @BIGAL This is not quite what I'm looking for but it will be very useful to me. Quote
BIGAL Posted February 28, 2019 Posted February 28, 2019 Its just me I am moving away from command line entry and taking advantage of mouse pick. I am just sorting out a as many as you like radio button dcl. But its still one line to call library code using a list for choices. Quote
JuniorNogueira Posted February 28, 2019 Author Posted February 28, 2019 1 hour ago, BIGAL said: É só eu estou me afastando da entrada de linha de comando e aproveitando a escolha do mouse. Eu estou apenas escolhendo um número que você goste do botão de rádio dcl. Mas ainda é uma linha para chamar o código da biblioteca usando uma lista de opções. @BIGAL Can you give me a simple example, how would it work for when I call the function when calling it again the option that I choose earlier is checked? Quote
BIGAL Posted February 28, 2019 Posted February 28, 2019 I updated the code above to a new "radio button multi.lsp" it allows any number of buttons without hard coding. I will add the default button as soon as I get time as it an extra variable in the defun. 1 Quote
BIGAL Posted March 14, 2019 Posted March 14, 2019 (edited) Try this the call would be for say you want "B" in A B C D its number 2 in list. I have not done the pre code part where you check which variable has been previously picked. needs a seperate little defun. ; Multi button Dialog box for a single choice repalcment of initget ; By Alan H Feb 2019 ; Example code as the radio button click will close the defualt button setting is required ; if you have defined a default setting ; (if (not AH:Butts)(load "Multi radio buttons.lsp")) ; (if (= ahdef nil)(setq ahdef 1)) ; this is needed to set default button ; (setq ans (ah:butts ahdef "V" '("A B C D " "A" "B" "C" "D" ))) ; ans holds the button picked value ; (setq butlst) ; (if (not AH:Butts)(load "Multi Radio buttons.lsp")) ; (if (= ahdef nil)(setq ahdef 1)) ; (setq ans (ah:butts ahdef "h" '("Yes or No" "Yes" "No"))) ; ans holds the button picked value (vl-load-com) (defun AH:Butts (def verhor butlst / fo fname x k ) (setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w")) (write-line "AHbutts : dialog {" fo) (write-line (strcat " label =" (chr 34) (nth 0 butlst) (chr 34) " ;" )fo) (write-line " : row {" fo) (if (= (strcase verhor) "V") (write-line " : boxed_radio_column {" fo) (write-line " : boxed_radio_row {" fo) ) (setq x 1) (repeat (- (length butlst) 1) (write-line " : radio_button {" fo) (write-line (strcat "key = " (chr 34) "Rb" (rtos x 2 0) (chr 34) ";") fo) (write-line (strcat "label = " (chr 34) (nth x butlst) (chr 34) ";") fo) (write-line " }" fo) (setq x (+ x 1)) ) (write-line " }" fo) (write-line " }" fo) (write-line "spacer_1 ;" fo) (write-line " ok_only;" fo) (write-line " }" fo) (close fo) (setq dcl_id (load_dialog fname)) (if (not (new_dialog "AHbutts" dcl_id) ) (exit) ) (setq x 1) (repeat (- (length butlst) 1) (setq k (strcat "Rb" (rtos x 2 0))) (action_tile k (strcat "(setq but " (rtos x 2 0) ")" "(done_dialog)")) (if (= ahdef x)(set_tile k "1")) (setq x (+ x 1)) ) (action_tile "accept" (strcat "(setq but " (rtos ahdef 2 0) ")" "(done_dialog)")) (start_dialog) (unload_dialog dcl_id) (vl-file-delete fname) (nth but butlst) ) Edited March 14, 2019 by BIGAL Quote
Recommended Posts
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.