yes, no variables

yes, no variables

f_rivaXGG6C
Contributor Contributor
936 Views
8 Replies
Message 1 of 9

yes, no variables

f_rivaXGG6C
Contributor
Contributor

I do not understand exactly what I have put wrong

 

This is an excerpt from a larger little program and I need to first ask some questions to those who are going to use the program and then run with the answers given above, since it will take me a while to run.

(defun c:comand ()
	(intget "Yes No")
	(setq Var1 (getkword "\n? [Yes/No]: <Yes> "))
	(setq Var2 (getkword "\n? [Yes/No]: <No> "))
	(if (= Var1 "Yes")
		(command "")
		()
	)
	(if (= Var2 "Yes")
		()
		(command "")
	)
	(setq Var1 nil)
	(setq Var2 nil)
)

 Can anyone explain exactly how these commands work?

 

Additional question:

Can i delete line 7?

 

Thank you!
🙂

0 Likes
Accepted solutions (2)
937 Views
8 Replies
Replies (8)
Message 2 of 9

ryanatkins49056
Enthusiast
Enthusiast
Accepted solution

If nothing goes between the brackets in lines 7 and 10 then you don't need them.

The initget featured in line 2 (to use for Var1) needs to be replicated for Var2. (Happy to be proven wrong as I've never had this circumstance but I believe there needs to be one for each getkword.)

Also you've mispelt initget in line 2 (you're missing the second i)

 

Therefore it should look like the following.

(defun c:comand ()
	(initget "Yes No")
	(setq Var1 (getkword "\n? [Yes/No]: <Yes> "))
        (initget "Yes No")
	(setq Var2 (getkword "\n? [Yes/No]: <No> "))
	(if (= Var1 "Yes")
		(command "")
	)
	(if (= Var2 "Yes")
		(command "")
	)
	(setq Var1 nil)
	(setq Var2 nil)
)

 

Also if you wish for the variables to be back to nil at the end you can localise them like so. (Look at line 1)

(defun c:comand ( / Var1 Var2)
	(initget "Yes No")
	(setq Var1 (getkword "\n? [Yes/No]: <Yes> "))
        (initget "Yes No")
	(setq Var2 (getkword "\n? [Yes/No]: <No> "))
	(if (= Var1 "Yes")
		(command "")
	)
	(if (= Var2 "Yes")
		(command "")
	)
)

 

0 Likes
Message 3 of 9

ryanatkins49056
Enthusiast
Enthusiast

Sorry I just saw the part you were asking how it works.

 

So the short version is that the initget allows for the input of keywords at the next function call. Hence why I said you need one for each getkword. The program is asking a question to establish rules of sorts. The initget function is prompting for preferred answers. Then after getting them its just

if Var1 was yes, 

true = do this

false = do nothing

if Var2 was yes, 

true = do this

false = do nothing

Message 4 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

In addition to needing (initget) prior to each (getkword) function:  Because of the wording of your prompts, you need to account for the possibility that someone will "accept the <offered default>" value in each case by hitting Enter.  In that case, the variable in question will be nil.  I would do something like this [note the expanded test expressions in lines 6 & 9]:

 

(defun c:comand ()
	(initget "Yes No")
	(setq Var1 (getkword "\n? [Yes/No]: <Yes> "))
	(initget "Yes No")
	(setq Var2 (getkword "\n? [Yes/No]: <No> "))
	(if (or (= Var1 "Yes") (not Var1))
		(command ""); then
	)
	(if (or (= Var2 "No") (not Var2))
		(command ""); then
	)
	(setq Var1 nil)
	(setq Var2 nil)
)

 

I note that since for your test on Var2 being "Yes," you have nothing as the 'then' argument, and the (command) function as your 'else' argument -- the reverse of the situation with Var1, including the offered default being the reverse.  So I reversed the test instead to check whether it's "No," and the (command) is then likewise the 'then' expression.

Kent Cooper, AIA
0 Likes
Message 5 of 9

f_rivaXGG6C
Contributor
Contributor

In the line 9, is (not Var1) correct?
just to confirm, also in case someone else finds this post useful

0 Likes
Message 6 of 9

Kent1Cooper
Consultant
Consultant

@f_rivaXGG6C wrote:

In the line 9, is (not Var1) correct?
just to confirm, also in case someone else finds this post useful


You're right -- it should be Var2 [corrected].  The old copy-without-fully-editing gremlin....

Kent Cooper, AIA
0 Likes
Message 7 of 9

Sea-Haven
Mentor
Mentor

Hi Kent, yep those 3 thumbs got in the way of the typo, "Intget", we are after all human. 

 

😁initget

 

0 Likes
Message 8 of 9

Sea-Haven
Mentor
Mentor

You could add a bit more text to the "Yes / No" describing what it is in reference to.

 

 

(setq Var1 (getkword "\nChange color ? [Yes/No]: <Yes> "))

 

I personally no longer use getkword, rather a global make dcl on the fly lisp. So for two yes/no something like this. Which includes a description.

 

SeaHaven_0-1727766161062.png

Above is 2 lines of code .

Can be pre set to on so select for off. Just ask if you think useful. Could also be a radio button DCL, then would have a yes and no button on two rows which toggle when clicked.

 

 

 

 

 

0 Likes
Message 9 of 9

Kent1Cooper
Consultant
Consultant

@Sea-Haven wrote:

Hi Kent, yep those 3 thumbs got in the way of the typo, "Intget", we are after all human. 

😁initget


That was just carried along from their original.  Also corrected now in mine.

Kent Cooper, AIA
0 Likes