Originally Posted by
sachindkini
Dear Sir,
thx for reply
yes. reuse the selection sets inside some lisp or inside a command
I'm still not clear as to how you want these. If you want to reuse the selection sets within some lisp, then do something like this:
Code:
(defun c:CommandName (/ n en ed)
(princ "\nSelect 1st set of entities: ")
(setq ss1 (ssget))
(princ "\nSelect 2nd set of entities: ")
(setq ss2 (ssget))
(princ "\nSelect 3rd set of entities: ")
(setq ss3 (ssget))
(princ "\nSelect 4th set of entities: ")
(setq ss4 (ssget))
;; Step through 1st selection set one at a time
(setq n 0)
(while (< n (sslength ss1))
(setq en (ssname ss1 n)) ;Get the ename of the nth entity in ss1
(setq n (1+ n)) ;Increment counter
)
;; Use the 2nd selection set in a copy command
(command "._COPY" ss2 "" pause)
(while (> (getvar "CMDACTIVE") 0) (command pause))
;; Various other ways of using the 4 selection sets in any order or any
;; number of times, until they are explicitly set to nil
(princ "\nSS1, SS2, SS3, SS4 are saved selection sets. Prefix with ! to use.")
(princ)
)
Note it saves the selection sets to 4 global variables which would thus be available to all other lisp functions. However, there's a limit on the amount of current selection sets ... so this is not a very good idea, but let's press on regardless .
If you want to reuse these as an argument for a command, then you could go with RK's example of prefixing the selection sets with an exclamation point (!) - as shown on the 2nd last line of the defun. Or you can create a wrapper function to send the selection set to the command line, e.g.
Code:
(defun c:s1 (/) (command ss1) (princ))
(defun c:s2 (/) (command ss2) (princ))
(defun c:s3 (/) (command ss3) (princ))
(defun c:s4 (/) (command ss4) (princ))
Then you can type 's1 / 's2 / 's3 / 's4 at the command prompt to invoke the lisp transparently. You can't send these "saved" selection sets to a lisp command argument. Not using lisp anyway.
Now here's my real question: how do you want to "create" these selection sets. When you say you want to reuse them in a command, the most usefull I can think of would be to have some form of Previous, 2ndPrevious, 3rdPrevious ....
If this is the case, then you'll need a command reactor to check if the previous selection set has changed. If so add it to a global list of selection sets, and discard the last from the list if the list reaches a predefined length (e.g. 4). Then you'll require a similar idea as per the wrapper functions above. For lisps to reuse these selection sets they can directly access the list. Unfortunately I don't see any way that the wrapper functions would pass the selection sets to other lisp functions when they ask for a selection through ssget.