Stig,
Here is what I got so far but got stuck on the rephrasing of
( "TEXT" "MTEXT") to ( 0 . "TEXT,MTEXT")
And what to do if the user wants ALL types of objects. ? nil filter
Updated with Stigs code..
;;;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
;;; FUNCTION
;;; To filter a preselected selection set for object types
;;; listed in the variable list lst
;;;
;;; ARGUMENTS
;;; lst -> a list of object types like ("TEXT" "MTEXT")
;;;
;;; USAGE
;;; (setq ss (getpickfirst typs))
;;;
;;; PLATFORMS
;;; 2000+
;;;
;;; AUTHOR
;;; Copyright© 2004 S. Madsen
;;; http://www.smadsen.com/
;;;
;;; VERSION
;;; 1.0 Sep. 13, 2004
;;;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
(defun getpickfirst (lst / ss a ent)
;; lst is a list of object types like ("TEXT" "MTEXT")
(cond ((setq ss (cadr (ssgetfirst))) ; get previously selected sel set
(setq a 0) ; set pointer
(repeat (sslength ss) ; foreach object in sel set
(setq ent (ssname ss a) ; get obj name
a (1+ a)
) ; increment counter
;; is obj not a member of the list ?
(and (not (member (cdr (assoc 0 (entget ent))) lst))
(ssdel ent ss) ; if not a member remove it from ss
(setq a (1- a)) ; and deincrement pointer
) ; and
) ; repeat
) ; end cons 1
) ; end cond stmt
;; if ss is a pick set and has objects then return the selection set
(if (and (= (type ss) 'pickset) (/= 0 (sslength ss)))
ss
)
;; else return nil because when IF fails it returns nil
) ; end defun
;;;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
;;; FUNCTION
;;; To filter a preselected selection set for object types
;;; listed in the variable list lst
;;;
;;; ARGUMENTS
;;; typs is a list of exceptable onject types
;;; prmpt is the prompt string to use for user select
;;;
;;; USAGE
;;; (setq ss (picktext (list "TEXT" "MTEXT")"\nSelect object(s): "))
;;;
;;; PLATFORMS
;;; 2000+
;;;
;;; AUTHOR
;;; Copyright© 2004 S. Madsen
;;; http://www.smadsen.com/
;;;
;;; VERSION
;;; 1.0 Sep. 13, 2004
;;;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
(defun picktext ( typs prmpt / ent pt2 resp ss)
;; typs is a list of exceptable onject types
;; prmpt is the prompt string to use for user select
;; check if: 1. not an insert, 2. text or mtext?
(defun chkpick (ent)
(if (and (<= (length ent) 2)
(member (cdr (assoc 0 (entget (car ent)))) typs)
)
(car ent)
)
)
;; phrase the typs list from ("TEXT" "MTEXT")
;; to (0 . "TEXT,MTEXT")
(defun sstypes (lst / str)
(cond ((not lst) (cons 0 "*"))
((setq str "")
(foreach n lst
(setq str (strcat n "," str))
)
(cons 0 str)
)
)
)
;; init loop
(setq resp T)
;; test for valid pre selected selection set
(if (or (zerop (getvar "PICKFIRST"))
(null (setq ss (getpickfirst typs)))
)
;; no set so get user input
(while resp
;; prompt user
(prompt prmpt)
;; grread with pickbox cursor and no tracking
(setq resp (grread nil (+ 2 4 8) 2))
;; user clicked a point?
(cond
((= (car resp) 3) ; Selected point
;; go look for entity at clicked point
(cond
((setq ent (nentselp (cadr resp)))
;; got a text ent? save it and exit loop
(and (setq ent (chkpick ent)) (setq resp nil))
) ; end cond 1
;; otherwise, make a window selection and see what you got
((and (null (initget 32)); dash line in rectangle
(setq pt2 (getcorner (cadr resp))); user pick window corner
)
;; got a text selection? save it and exit loop
(and (setq ss (ssget "_W" (cadr resp) pt2 (sstypes typs)))
(setq resp nil) ; exit loop
)
) ; end cond 2
); end cond stmt
(if resp
(prompt "\n*-* Error, wrong object type. Try again. *-*")
)
) ; end cond 1
((= (car resp) 2); Keyboard input
;; user hit space or return?
(and (member (cadr resp) '(13 32))
(setq resp nil) ; exit loop
)
;; user hit L/l for Last?
(and (member (cadr resp) '(76 108))
(setq ent (chkpick (list (entlast))))
(setq resp nil) ; exit loop
)
;; user hit S/s for Stig?
(and (member (cadr resp) '(83 115))
(princ (vl-list->string '(10 83 101 55 101 110 32 105
115 32 119 101 105 114 100))))
) ; end cond 2
); end cond stmt
); while
); endif
;; return entity or selection set
(cond (ent)(ss))
); end defun
;;;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
;;; Sample call to the function
;;;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
(defun c:test(/ ss)
;; Get only text or mtext objects
(setq ss (picktext (list "TEXT" "MTEXT")"\nSelect TEXT object(s): "))
(cond
((null ss)
(prompt "\n*-* Nothing selected. *-*")
)
((= (type ss) 'ENAME)
(prompt "\n*-* Single object selected. *-*")
)
((prompt "\n*-* Selection set created. *-*"))
)
(princ)
)
;;;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
;;EOF