;;;--------------------ssseg------------------------------------ ;;; Author: Herman Mayfarth ;;; Purpose: Segregates a selection set containing multiple ;;; entity types into an association list of the form: ;;; (("TYPESTRING1" . ) ("TYPESTRING2" . ) etc.) ;;; where each selection set contains the entities of ;;; type described by "TYPESTRINGn" ;;; Param: Selection set, as above ;;; Returns: Association list if successful, else nil ;;;------------------------------------------------------------ (defun ssseg (arg / i iname itype n posit sslst typlst dxf ssp ) ;;local functions (defun dxf (code ent) (cdr (assoc code (entget ent)))) (defun ssp (arg) (if (= 'PICKSET (type arg)) (sslength arg) ) ) ;;first check to see if the argument is a PICKSET (if (setq n (ssp arg)) ;;if we have a PICKSET (progn ;;initialize entity counter (setq i 0.0 ;; get the first entity in the selection set and create two lists typlst (list (dxf 0 (ssname arg i))) sslst (list (ssadd (ssname arg i))) ) ;; step through remainder of arg and segregate the entities by type (repeat (1- n) (progn (setq i (1+ i)) (setq iname (ssname arg i) itype (dxf 0 iname) posit (vl-position itype typlst) ) ;;if the type is already in typlst (if posit ;;add this item to its associated selection set (ssadd iname (nth posit sslst)) ;;otherwise add the type to typlst, ;; then create a new selection set for this type & add it to sslist (setq typlst (cons itype typlst) sslst (cons (ssadd iname) sslst) ) ) ;if ) ;progn ) ;repeat ;;construct the return value (mapcar 'cons typlst sslst) ) ;progn ) ;if ;;otherwise return nil ) ;ssseg