Jump to content

Recommended Posts

Posted

(getstring (strcat "<" "Test" ">"))

Works like in the picture.

 

Getstring1.jpg

 

Is it possible to do not print the default value?

Just like the picture below.

 

Getstring2.jpg

Posted

Your looking for this?

(setq thestring (getstring "\nEnter string <TEST>: "))
(if (null thestring)(setq thestring "TEST"))

When there is no imput, the value is set to "TEST".

this part:

(getstring "\nEnter string <TEST>: ")

is just cosmetic, and could also be:

(getstring "\nEnter string: ")

Posted

I have a variable string:

(setq a "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")

 

I want to modify it using the function getstring

(getstring (strcat "<" a ">"))

That is now:

 

Getstring3.jpg

 

I want to have it without a prefix.

 

Getstring4.jpg

 

Is it possible?

Posted

@Kowal:

If you don't want this prompt why are you providing it?

Posted

If I'm understanding you correctly, you're just missing the brackets: (getstring (strcat "[]"))

Posted
If I'm understanding you correctly, you're just missing the brackets: (getstring (strcat "[]"))

 

Nice Ron, this is new for me!

Perhaps to make an useful prompt from this would be:

(cond ((= (setq v (getstring (strcat "[<" a ">]"))) "") a)(v))

Posted
Nice Ron, this is new for me!

Perhaps to make an useful prompt from this would be:

(cond ((= (setq v (getstring (strcat "[<" a ">]"))) "") a)(v))

Definitely :)

 

I use something like this a lot for getkword:

(or *default* (setq *default* "Width"))
(initget (setq options "Arc Length Width"))
(setq *default*	(cond ((getkword (strcat "\nPick an option: ["
				 (vl-string-translate " " "/" options)
				 "] <"
				 *default*
				 ">:"
			 )
	       )
	      )
	      (*default*)
	)
)

2018-02-02_10-22-39.png

Posted

Thank you ronjonp. I was looking for such a solution.

Posted

Ronjonp are we missing a defun ? Just got the normal input on command line.

 

My $0.05 with multiple key words can use a dcl list box method and pick only one. Need a library routine routine for the dcl but basicly 3 lines of code. Thanks to lee for listbox.

 

(if (not LM:listbox)(load "ListBoxV1-2.lsp")) ; loads the lisp if not already loaded
(setq lst (list "Stone" "Ceramic" "Plastic"))
(setq ans (nth 0 (LM:listbox "Pick material" lst 1))) ; calls the list box and return item

Posted
Ronjonp are we missing a defun ? Just got the normal input on command line.

 

My $0.05 with multiple key words can use a dcl list box method and pick only one. Need a library routine routine for the dcl but basicly 3 lines of code. Thanks to lee for listbox.

 

(if (not LM:listbox)(load "ListBoxV1-2.lsp")) ; loads the lisp if not already loaded
(setq lst (list "Stone" "Ceramic" "Plastic"))
(setq ans (nth 0 (LM:listbox "Pick material" lst 1))) ; calls the list box and return item

 

Not missing a defun just a simple example. You'll need to set dynmode to 1 to get the result at the cursor.

Posted (edited)

Thanks thought it would be a switch somewhere as you know there are so many. Need Dynprompt = 1 also. I work with the dynamics turned off a personal preference.

 

Ronjonp I like the idea so made it a library function, will probably use in future as I am moving my code away from command line input to a more in your face approach.

 

; get keyword on screen input by Ronjonp Jan 2018
;http://www.cadtutor.net/forum/showthread.php?102708-Getstring-a-default-value-without-print.
; modified by BIGAL Jan 2018 as a library function

(defun keyword (*default* options /  )
(setq olddynmode (getvar "dynmode"))
(setq olddynprompt (getvar "dynprompt"))
(setvar "dynmode" 1)
(setvar "dynprompt" 1)
(initget options )
(setq *default* (cond ((getkword (strcat "\nPick an option: ["
	   (vl-string-translate " " "/" options)
	      "] <"
	      *default*
	     ">:"
	  )
	  )
	  )
	      (*default*)
	  )
)
(setvar "dynmode" olddynmode)
(setvar "dynprompt" olddynprompt)
)

; example 
(keyword "Width" "Length Height Width")

Edited by BIGAL
Posted

Glad you could use it :). I generally draft with the dynmode set to 0 as well for performance. IMO .. I'd put an error function in that if you're changing variables within the function.

Posted

ronjonp good idea I have been meaning to write a bit of a reset lots error function as a library function, often need filedia reset.

Posted

Maybe something like this so you don't have a common global which might cause problems.

(defun keyword (key options default / *error* def vars)
 (defun *error* (msg)
   (mapcar '(lambda (x) (setvar (car x) (cdr x))) vars)
   (if	(not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
     (princ (strcat "\nError: " msg))
   )
   (princ)
 )
 (or (setq def (getenv key)) (setq def default))
 (setq vars (mapcar '(lambda (x) (cons x (getvar x))) (list 'dynmode 'dynprompt)))
 (mapcar '(lambda (a b) (setvar (car a) b)) vars '(1 1))
 (initget options)
 (setq	def
 (cond ((getkword
	  (strcat "\nPick an option: [" (vl-string-translate " " "/" options) "] <" def ">:")
	)
       )
       (def)
 )
 )
 (mapcar '(lambda (x) (setvar (car x) (cdr x))) vars)
 (setenv key def)
)
(keyword "MyProgram" "Length Height Width Depth" "Height")

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