- (defun c:test (/ ss i j ent ents ang item lst str intlst xl-sort xl-isort To)
- ;(xl-sort lst fun) = 以取代vl-sort函数,用法相同(lsp)---------------by 无痕
- (defun xl-sort (lst fun / nlst)
- (foreach n lst (setq nlst (xl-isort n nlst fun)))
- )
- (defun xl-isort (item lst fun / k nlst)
- (setq k T
- nlst (apply 'append
- (mapcar '(lambda (x)
- (if (and K ((eval fun) item x))
- (progn (setq k nil) (list item x))
- (list x)
- )
- )
- lst
- )
- )
- )
- (if k
- (append lst (list item))
- nlst
- )
- )
- (defun To (entlst / str ents)
- (setq str (apply 'strcat
- (mapcar '(lambda (e) (cdr (assoc 1 e))) entlst)
- )
- )
- (setq ents (subst (cons 1 str) (assoc 1 (car intlst)) (car entlst)))
- (entmod ents)
- (mapcar 'entdel
- (mapcar '(lambda (e) (cdr (assoc -1 e))) (cdr entlst))
- )
- )
- (setq ss (ssget '((0 . "TEXT"))))
- (setq i 0)
- (setq lst nil
- intlst nil
- )
- (repeat (sslength ss)
- (setq ent (ssname ss i))
- (setq ents (entget ent))
- (setq ang (cdr (assoc 50 ents)))
- (if (setq item (assoc ang lst))
- (setq lst (subst (append item (list ents)) item lst))
- (setq lst (append lst (list (list ang ents))))
- )
- (setq i (1+ i))
- )
- (setq i 0)
- (setq lst
- (mapcar
- '(lambda (e)
- (cons
- (car e)
- (vl-sort (cdr e)
- '(lambda (e1 e2)
- (< (cadr (assoc 10 e1)) (cadr (assoc 10 e2)))
- )
- )
- )
- )
- lst
- )
- )
- (repeat (length lst)
- (setq item (nth i lst))
- (setq j 1)
- (repeat (1- (length item))
- (setq ents (nth j item))
- (setq str (cdr (assoc 1 ents)))
- (if (= (type (read str)) 'INT)
- (setq intlst (append intlst (list ents)))
- (if intlst
- (progn
- (To intlst)
- (setq intlst nil)
- )
- )
- )
- (setq j (1+ j))
- )
- (if intlst
- (To intlst)
- )
- (setq i (1+ i))
- )
- (princ)
- )
|