Try this:
; Marc'Antonio Alessi, Italy - http://xoomer.virgilio.it/alessi
;
; Function: ALE_EntSelFilter
;
; Version 1.00 - 22/02/2005
; Version 1.01 - 04/03/2006 - added (setvar "ERRNO" 0)
;
; Description:
; Ssget for one entity with filter list
;
; Arguments:
; PrmStr = User prompt [STR]
; FltLst = ssget filter list [LIST]
;
; Example:
; (ALE_EntSelFilter "Select attibuted block" '((0 . "INSERT") (66 . 1)))
;
; Return Values:
; [ENAME] Entity name
; nil if user press 'Return' or 'Space'
;
(defun ALE_EntSelFilter (PrmStr FltLst / FlgSlt EntNam)
(setvar "ERRNO" 0)
(princ "\n_ ")
(prompt (setq PrmStr (strcat "\n" PrmStr ": ")))
(if
(while (not FlgSlt)
(if (setq EntNam (ssget "_:E:S" FltLst))
(not (setq FlgSlt T))
(if (= 52 (getvar "ERRNO"))
(setq FlgSlt T)
;|e|; (prompt (strcat "\nNo objects selected or valid, try again!" PrmStr))
)
)
)
;|e|; (not (princ "\nFunction cancelled. "))
(ssname EntNam 0)
)
)
;
; Marc'Antonio Alessi, Italy - http://xoomer.virgilio.it/alessi
;
; Function: ALE_N-EntSelEntity
;
; Version 1.00 - 22/02/2005
; Version 1.01 - 04/03/2006 - added (setvar "ERRNO" 0)
;
; Description:
; enhanced EntSel or NentSel
;
; Arguments:
; PrmStr = User prompt [STR]
; SelTyp = Selection type [SYM]: 'entsel or 'nentsel
; WcMStr = Wcmatch string [STR]
; ex.: "Line,*Polyline,Arc,Circle,Ellipse,Spline"
;
; Example:
; (ALE_N-EntSelEntity "Select block" 'entsel "Insert")
; (ALE_N-EntSelEntity "Select text or attrib (also nested)" 'nentsel "Text,Attrib")
;
; Return Values:
; [LIST]: see entsel or nentsel
; nil if user press 'Return' or 'Space'
;
(defun ALE_N-EntSelEntity (PrmStr SelTyp WcMStr / FlgSlt SelLst)
(setvar "ERRNO" 0)
(princ "\n_ ")
(setq PrmStr (strcat "\n" PrmStr ": "))
(if
(while (not FlgSlt)
(if
(and
(setq SelLst ((eval SelTyp) PrmStr))
(wcmatch (DXF 0 (entget (car SelLst))) (strcase WcMStr))
)
(not (setq FlgSlt T))
(if (= 52 (getvar "ERRNO"))
(setq FlgSlt T)
;|e|; (princ (strcat "\nNo entity selected or it is not a: " WcMStr "!"))
)
)
)
;|e|; (not (princ "\nFunction cancelled. "))
SelLst
)
)