Jump to content

How to save a value which has given to an argument ?


Sweety

Recommended Posts

Hello GUYS. :)

 

How could I save the value to the argument ( Len ) to be used once again in the same routine by pressing Enter ?

 

(initget (+ 2 4))
(setq Len (getdist "\n SpecifyLength of the element :"))

 

Thankxxxxxxxxxxxx

Link to comment
Share on other sites

Some information I have given in the past:

 

;; Initget / GetK(ey)word Examples
;; © Lee Mac 2010

;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

;; Note 1: On Prompt String Format

;; In all examples, to achieve correct display
;; when DYNamic Input (DYNMODE=1) is enabled,
;; prompt string must be formatted thus:

;; [Option1/Option2/Option3]

;; Or, with default:

;; [Option1/Option2/Option3] <Option1>

;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

;; Note 2: On Global Variable Format

;; In all examples utilising global variables
;; asterisks are included in variable names to decrease
;; risk of variable names clashing with unlocalised variables
;; from other programs. Asterisks are used for no other purpose.

;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

;; 1. Force User Input (initget bit 1)

(initget 1 "Alpha Beta Gamma")
(setq ans (getkword "\nChoose [Alpha/Beta/Gamma]: "))

;; User must select a choice to continue, else
;; Esc must be used to cancel evaluation

;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

;; 2. Preset Default (Alpha)

;; a)

(initget "Alpha Beta Gamma")
(setq ans (cond ( (getkword "\nChoose [Alpha/Beta/Gamma] <Alpha>: ") ) ( "Alpha" )))

;; b)

(initget "Alpha Beta Gamma")
(setq ans (getkword "\nChoose [Alpha/Beta/Gamma] <Alpha>: "))

(if (not ans) (setq ans "Alpha"))

;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

;; 3. Dynamic Default (utlisation of Global Variable: *ans*)

;; a)

(or *ans* (setq *ans* "Alpha"))

(initget "Alpha Beta Gamma")
(setq *ans*
 (cond
   (
     (getkword
       (strcat "\nChoose [Alpha/Beta/Gamma] <" *ans* ">: ")
     )
   )
   ( *ans* )
 )
)

;; b)

(if (not *ans*) (setq *ans* "Alpha"))

(initget "Alpha Beta Gamma")
(setq *ans*
 (cond
   (
     (getkword
       (strcat "\nChoose [Alpha/Beta/Gamma] <" *ans* ">: ")
     )
   )
   ( *ans* )
 )
)

;; c)

(initget "Alpha Beta Gamma")
(setq *ans*
 (cond
   (
     (getkword
       (strcat "\nChoose [Alpha/Beta/Gamma] <"
         (setq *ans*
           (cond ( *ans* ) ( "Alpha" ))
         )
         ">: "
       )
     )
   )
   ( *ans* )
 )
)








Link to comment
Share on other sites

I hope this example match your needs

(if (not rnm:Pref)
   (setq rnm:Pref "")
 )
(setq rnm:Pref
 (getstring
   T
   (strcat
     "\nType prefix:(If you want to delete prefix type ' ' (press SPACE key on keyboard) <"
     rnm:Pref
     "> :"
   )
 )
 )

Link to comment
Share on other sites

I hope this example match your needs

(if (not rnm:Pref)
   (setq rnm:Pref "")
 )
(setq rnm:Pref
 (getstring
   T
   (strcat "\nType prefix:(If you want to delete prefix type ' ' (press SPACE key on keyboard) <" rnm:Pref "> :"
   )))

 

It's not. Because you should (cond) function plus (T + argument) .

 

And when you hit enter it will return "nil" .

 

Try again.

Link to comment
Share on other sites

Here's how I do it:

 

[b][color=BLACK]([/color][/b]setq ldef [b][color=FUCHSIA]([/color][/b]if deflen deflen 28[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]
[b][color=BLACK]([/color][/b]initget 6[b][color=BLACK])[/color][/b]
[b][color=BLACK]([/color][/b]setq len [b][color=FUCHSIA]([/color][/b]getdist [b][color=NAVY]([/color][/b]strcat [color=#2f4f4f]"\nLength <"[/color] [b][color=MAROON]([/color][/b]rtos ldef 2 2[b][color=MAROON])[/color][/b] [color=#2f4f4f]">:   "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]
[b][color=BLACK]([/color][/b]or len [b][color=FUCHSIA]([/color][/b]setq len ldef[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]
[b][color=BLACK]([/color][/b]setq deflen len[b][color=BLACK])[/color][/b]

 

The default is 28 the first time the program is run. The default changes with the current inputs. len needs to be localized as does ldef

 

I leave deflen global so that it can be used with other programs.

 

This could probably be compressed a some, but it is readable for me anyway. -David

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