Jump to content

What's the smarter way to do this?


Recommended Posts

Posted

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

Posted (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 by ronjonp
  • Like 1
Posted
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)
	  )
)

 

  • Thanks 1
Posted (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 by Lee Mac
  • Like 1
Posted
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. :)

  • Like 1
Posted (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 by BIGAL
  • Like 1
Posted

Very very much thank you guys !! 😍😍   @BIGAL This is not quite what I'm looking for but it will be very useful to me.

Posted

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.

Posted
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?

Posted

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.

  • Like 1
  • 2 weeks later...
Posted (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 by BIGAL

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