Can a SETQ selection set be programmed to the last selection?

Can a SETQ selection set be programmed to the last selection?

murmanator
Advocate Advocate
2,990 Views
21 Replies
Message 1 of 22

Can a SETQ selection set be programmed to the last selection?

murmanator
Advocate
Advocate

Im not sure if Im saying that right. I use this little snippet of code in a lot of programs (with different lists of course depending on the program). As I understand it, the part that reads <POOL> and ("POOL") define the default choice in the display and the selection. Ive removed those and there is no default, you must select something. What I want to know is if there is a way to use that part of the code to make the selection whatever the last selection was, instead of a defined default or none. Thank you

 

(IF (NULL TYP)
(PROGN (INITGET "POOL SPA THERAPY WTR-FEATURE")
(SETQ TYP (COND ((GETKWORD "\nSpecify Layer [POOL/SPA/THERAPY/WTR-FEATURE] <POOL>: "))
("POOL")
)
)
)
)

0 Likes
Accepted solutions (1)
2,991 Views
21 Replies
Replies (21)
Message 2 of 22

CodeDing
Mentor
Mentor
Accepted solution

@murmanator ,

 

This should do:

(if (null typ)
  (progn
    (initget "POOL SPA THERAPY WTR-FEATURE")
    (setq typ (cond
                ((getkword (strcat "\nSpecify Layer [POOL/SPA/THERAPY/WTR-FEATURE] <" (cond (*prevTyp*) ("POOL")) ">: ")))
                ((cond (*prevTyp*) ("POOL")))
              );cond
          *prevTyp* typ
    );setq
  );progn
);if

 

Best,

~DD

0 Likes
Message 3 of 22

john.uhden
Mentor
Mentor

@murmanator ,

This construct should do the job.

What it does is save the subsequent selection set symbol name as the concatenation of the first letter of the chosen typ (P, S, T, W) and the characters "ss."

BTW, don't use all capitals for your initget words.  Just capitalize say the first letter, then the user can enter just "S" to choose the "Spa" option, etc.

(defun test ( / typ filter ss)
  (INITGET "Pool Spa Therapy Wtr-feature")
  (SETQ TYP (GETKWORD "\nSpecify Layer [Pool/Spa/Therapy/Wtr-feature] <POOL>: "))
  (cond
    ((or (not typ)(= typ "Pool")) (setq ss 'Pss))
    ((= typ "Spa")(setq ss 'Sss))
    ((= typ "Therapy")(setq ss 'Tss))
    ((= typ "Wtr-feature")(setq ss 'Wss))
  )
  (setq filter (list ...))
  (set ss (ssget "CP" filter))
  ;; Do your stuff here
  (princ)
)

John F. Uhden

0 Likes
Message 4 of 22

Kent1Cooper
Consultant
Consultant

Just to clarify:  By "selection," I think you mean choice of an option word, not the more common AutoLisp usage of the word as being about object selection.  It looks like @john.uhden's suggestion assumes at least in part that it's about object selection.  @CodeDing 's looks to me more like what I think you're asking about, offering your previous option choice [if there is one] as the default each time [with an initial default choice for the first time], not always the same default.

Kent Cooper, AIA
0 Likes
Message 5 of 22

komondormrex
Mentor
Mentor

maybe this one

 

(setq sel_layer t)
(while sel_layer
	(progn (initget "POOL SPA THERAPY WTR-FEATURE")
		(setq sel_layer (not (setq typ (getkword "\nSpecify Layer [POOL/SPA/THERAPY/WTR-FEATURE]: "))))
	)
)

 

 

0 Likes
Message 6 of 22

dbroad
Mentor
Mentor
;|Another approach is to use princ to prompt the question and
then to use a library function to manage the details of the keyword
formatting and default process.  In order to use the previously selected
keyword, you would need to start with the default set to an often used
selection or to nil.  Nil would require a selection from the user.
|;
(princ "\nSelect layer");Root of prompt without options
(setq globaltmp (gk$ "Pool Spa Therapy Wtr-feature" globaltmp));GK$ library getkword
;;What follows is what you would do with the choice such as
(Cond
  ((= globaltmp "Pool")
   ;do stuff for pool
   )
  ....
  (t (*error* "Choice not expected in layer selection.")))
;or just set the layer assuming it exists
(setvar "clayer" globaltmp)

The library code I wrote over 30 years ago is:

;;get keyword with default (prompt is keyword string)------------------//
;;(gk$ "prompt" default)
(defun GK$  (PR DF / GK$TMP)
  (initget (if DF
	     0
	     1)
	   PR)
  (setq	GK$TMP
	 (getkword
	   (if DF
	     (strcat "["
		     (vl-string-translate " " "/" PR)
		     "]<"
		     DF
		     ">: ")
	     (strcat "[" (vl-string-translate " " "/" PR) "]: "))))
  (cond	(GK$TMP)
	(DF)))

At the command line, the two line code (princ and setq )above looks like this the first time if globaltmp is nil

Select layer[Pool/Spa/Therapy/Wtr-feature]: 

The second time, it looks like this if Pool previously selected

Select layer[Pool/Spa/Therapy/Wtr-feature]<Pool>:

 

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 7 of 22

john.uhden
Mentor
Mentor

@Kent1Cooper ,

Yes, I believe that I took the request to mean saving multiple selection sets for recall, not just the previous one.  Do  you think I should add that in or let @dbroad 's response cover it?

John F. Uhden

0 Likes
Message 8 of 22

john.uhden
Mentor
Mentor

Wait a second.  I think maybe others but certainly myself have this backwards.

What's the point of asking for a selection set name if it hasn't yet been saved?

I think that rather he wants to create a selection set, do some operations, and then save the selection set as a name so that later he can recall it when asked to select objects.  But I don't see a way to intercept the ssget function or even detect its use with a reactor.

John F. Uhden

0 Likes
Message 9 of 22

dbroad
Mentor
Mentor

I was assuming, based on his code, not the thread title, that he wanted to save a response as default, instead of a "selection set", that he really wanted to save a selected "response" to the set of keywords so it could serve as a default the next time the question was asked at the same point in the same command program.  If it turns out that I interpreted the question correctly, the forum manager should retitle the thread IMO. If he's really naming selection sets, which I assume is impossible, he's a better coder than me. I can just save them in symbols.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 10 of 22

Kent1Cooper
Consultant
Consultant

@dbroad wrote:

I was assuming, based on his code, not the thread title, that he wanted to save a response as default, instead of a "selection set", that he really wanted to save a selected "response" to the set of keywords so it could serve as a default the next time ....


That was my question in Message 4.  We have not yet heard back from @murmanator about what they meant by the word "selection."

Kent Cooper, AIA
0 Likes
Message 11 of 22

john.uhden
Mentor
Mentor

@dbroad and @Kent1Cooper ,

I understand your concern, but what can only a string response do?

What with more than one choice, I still think that he wants to recall a selection set other than "Previous."

Maybe the best way is to save only a filter for each of the choices, perhaps as a global variable, or to the bulletin board, or as vlax-ldata.  However, the ssget function is very particular about the point list and filter sent to it.  F'rinstance you can't use a point list of nil (at least in 2002).  But you could get a point list (if required for C or W or CP or WP or F) within a higher function that calls ssget.

John F. Uhden

0 Likes
Message 12 of 22

Sea-Haven
Mentor
Mentor

My $0.05 sounds like use a Set function where you define the prior selection to be a chosen variable name.

 

(set (read "pool") ss)

 

I don't use initget any more, as I have mentioned before.

 

(if (not AH:Butts)(load "Multi radio buttons.lsp")) ; loads the program if not loaded already
(if (= but nil)(setq but 1)) 	; this is needed to set default button
(setq ans (ah:butts but "V"   '("Please choose " "Pool" "Spa" "Therapy" "Water-feature" ))) 	; ans holds the button picked value as a string

 

SeaHaven_0-1730687812966.png

 

Message 13 of 22

dbroad
Mentor
Mentor

I set up macros years ago that let me set save and reuse 2 or 3 selection sets.  Today, I just use groups, usually unnamed.  As opposed to selection sets, groups are retained between drawing sessions.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 14 of 22

Sea-Haven
Mentor
Mentor

Good idea using groups. You can use the set to say keep making variables, (strcat "sel" (rtos x 2 0)) as many selections as you like. 

0 Likes
Message 15 of 22

Kent1Cooper
Consultant
Consultant

[I still think that by "selection" you mean "option," but for those interested in selection sets of objects, a related topic is where you will find SelSetStack.lsp, >here<.  It's for creating multiple selection sets that you can cycle through.  Read the description of how it works at Message 3 there.]

Kent Cooper, AIA
0 Likes
Message 16 of 22

murmanator
Advocate
Advocate

So, please forgive my ignorance on the correct terminology of code and how I described my request. What I was looking to achieve is, from the user perspective, is if you run this program and pick SPA and run the program to the end, then run it again it defaults to SPA without you needing to pick it. As opposed to how I posted the code which will default to POOL every time. I will try a few of the code suggestions here. Thank you all.

0 Likes
Message 17 of 22

murmanator
Advocate
Advocate

This does exactly what I was looking for. Thank you and thanks to everyone for helping.

0 Likes
Message 18 of 22

ВeekeeCZ
Consultant
Consultant

As you  "use this little snippet of code in a lot of programs (with different lists of course depending on the program)."

 

...be aware that the solution snipped uses a GLOBAL variable called *prevTyp*... - you should use a different name in other programs to avoid interferences.

0 Likes
Message 19 of 22

murmanator
Advocate
Advocate

John, thanks for the tip on capitalization. I ran into some trouble awhile back NOT using all caps where I had multiple options with the same first letter. I had to cap the second/third letters for it all to work right (there needed to be unique capitalized letters leading off each word) . From that point on I just used all caps, but I see your point.

0 Likes
Message 20 of 22

murmanator
Advocate
Advocate
I noticed that while testing, thanks for the tip.
0 Likes