本帖最后由 作者 于 2004-10-15 13:40:28 编辑
文件存在c:\abc.txt下- (defun c:test( / ss i j n entlst ent ents ents2 line_lst lst filename f xmin m)
- (setq ss (ssget '((0 . "TEXT"))))
- (setq i 0)
- (repeat (sslength ss)
- (setq entlst (append entlst (list (ssname ss i))))
- (setq i (1+ i))
- )
- (setq entlst (vl-sort entlst '(lambda(e1 e2) (<
- (cadr (assoc 10 (entget e1)))
- (cadr (assoc 10 (entget e2)))
- ))))
- (setq entlst (vl-sort entlst '(lambda(e1 e2) (<
- (caddr (assoc 10 (entget e1)))
- (caddr (assoc 10 (entget e2)))
- ))))
- (setq i 0 n (length entlst))
- (while (< i (1- n))
- (setq ent (nth i entlst))
- (setq line_lst nil)
- (setq line_lst (append line_lst (list ent)))
- (setq ents (entget ent))
- (setq j (1+ i) m t)
- (while m
- (setq ent (nth j entlst))
- (setq ents2 (entget ent))
- (if (equal (caddr (assoc 10 ents)) (caddr (assoc 10 ents2)) 0.001)
- (setq line_lst (append line_lst (list ent)))
- (progn
- (setq lst (append lst (list line_lst)))
- (setq m nil)
- (setq i j)
- )
- )
- (setq j (1+ j))
- (if (>= j n)
- (progn (setq lst (append lst (list line_lst))) (setq m nil) (setq i j))
- )
- )
- )
- (setq lst (mapcar '(lambda(x)
- (mapcar '(lambda(x / ents)
- (setq ents (entget x)) (cons (cadr (assoc 10 ents)) (cdr (assoc 1 ents))))
- x))
- lst))
- (setq xmin (apply 'min (mapcar '(lambda(x) (caar x)) lst)))
- (setq filename "c:\\abc.txt")
- (setq f (open filename "w"))
- (mapcar '(lambda(x / i item str m)
- (setq i 0 m 0)
- (setq str "")
- (repeat 4
- (setq item (nth (- i m) x))
- (if (and item (equal (- (car item) xmin) (* i 30.0) 0.001))
- (setq str (strcat str (cdr item) "\t"))
- (progn
- (setq str (strcat str """" "\t"))
- (setq m (1+ m))
- )
- )
- (setq i (1+ i))
- )
- (write-line (strcat "(" str ")") f)
- );lambda
- lst
- );mapcar
- (close f)
- (princ)
- )
|