PDA

View Full Version : Remember previous selection in a list


Mr Cory
2008-03-06, 12:23 AM
Hi Everyone

Is it possible to for to build into the following lisp something make CAD remember the previous selection, well more that it defaults to the last selection and that the user can just hit enter again without having to type the selection.

(defun c:sv (/ ss ssnam);Set1 Set2 Set3 Set4
(setq ss (ssget));gets the initial selection set
(initget "1 2 3 4");sets the keywords for the getkword function.
(setq ssnam (getkword "\nSelect which selection set to add objects to. [1/2/3/4] <1>"));prompts the user
(if (null th) (setq th 1))
(cond
;;Assigns the selection set to the proper variable
((= ssnam "1") (setq Set1 ss))
((= ssnam "2") (setq Set2 ss))
((= ssnam "3") (setq Set3 ss))
((= ssnam "4") (setq Set4 ss))
); End cond
(princ); Exit Quietly
)

Adesu
2008-03-06, 02:10 AM
Hi Mr Cory,
I think your code is right and set your variable as global.

Mr Cory
2008-03-06, 02:44 AM
Thanks Adesu, yeah the code works fine as it is, but im just trying to get it to remember what had been option had been selected before.

Say i run the command and select set2 and carry on working then i run the command again but instead of set1 being the default i would like set2 to be the default as it was the last option to be selected.

Sorry i didnt explain every well the first time

Gerhardt.Nortje
2008-03-06, 06:10 AM
Hi Cory

My additions might not be very elegant but I think it accomplishes what you want.


(defun c:sv (/ ss );Set1 Set2 Set3 Set4
(if (not ssnam) (setq ssnam "1"))
(setq ss (ssget));gets the initial selection set
(initget "1 2 3 4");sets the keywords for the getkword function.
(setq ssnamnew (getkword
(strcat "\nSelect which selection set to add objects to. [1/2/3/4] <" ssnam ">")
)
);prompts the user
(if ssnamnew (setq ssnam ssnamnew))
;(if (null th) (setq th 1))
(cond
;;Assigns the selection set to the proper variable
((= ssnam "1") (setq Set1 ss))
((= ssnam "2") (setq Set2 ss))
((= ssnam "3") (setq Set3 ss))
((= ssnam "4") (setq Set4 ss))
); End cond
(princ); Exit Quietly
)


Regards
Gerhardt

irneb
2008-03-06, 06:18 AM
You can try changing to this, changes marked in RED:;; Save global default choice
(setq $ssName "1")
(defun c:sv (/ ss ssnam) ;Set1 Set2 Set3 Set4
(setq ss (ssget)) ;gets the initial selection set
(initget "1 2 3 4") ;sets the keywords for the getkword function.
(setq ssnam
(getkword
(strcat "\nSelect which selection set to add objects to. [1/2/3/4] <" $ssName ">")
) ;_ end of getkword
) ;prompts the user
(if (not ssnam)
(setq ssnam $ssName)
)
(if (null th)
(setq th 1)
) ;_ end of if
(cond
;;Assigns the selection set to the proper variable
((= ssnam "1") (setq Set1 ss $ssName ssnam))
((= ssnam "2") (setq Set2 ss $ssName ssnam))
((= ssnam "3") (setq Set3 ss $ssName ssnam))
((= ssnam "4") (setq Set4 ss $ssName ssnam))
) ; End cond
(princ) ; Exit Quietly
) ;_ end of defun

Mr Cory
2008-03-06, 08:23 PM
Thank you both for your effort much appreciated!! They both seem to work, cheers :beer::beer::beer:

CAB2k
2008-03-09, 07:14 AM
My version.
;; CAB 03.08.08
;; Save a user picked selection set in one of 4 named
;; selection sets, Set1 Set2 Set3 Set4
(defun c:sv (/ ss Choice)
(if (or (setq ss (cadr (ssgetfirst)))
(and (princ "\nFor your saved selection set,")
(setq ss (ssget))))
(progn
(or *ssLast* (setq *ssLast* "1"))
(initget "1 2 3 4")
(setq Choice
(getkword
(strcat "\nSelect selection set to add objects to. [1/2/3/4] <"
*ssLast* ">")))
(and Choice (setq *ssLast* Choice))
(set (read (strcat "Set" *ssLast*)) ss)
(sssetfirst nil)
)
)
(princ)
)