本帖最后由 煮茗 于 2024-12-15 14:27 编辑
- ;选择闭合多段线,从左到右从上到下排序编号
- (defun c:tt (/ FN FFILE SS I ENTS EN PT EN1 PTS PTLST STRLST)
- (VL-LOAD-COM )
- (initget 1 "Y N")
- (setq write (getkword "\n 是否加入前缀 (Y)是 (N)否:"))
- (if (wcmatch write "Y")
- (setq str (getstring "\n 请输入前缀"))
- )
- (if <span style="background-color: rgb(255, 255, 255);">(setq ss (ssget '((0 . "LWPOLYLINE") (-4 . "&") (70 . 1))))</span>
- (progn
- (setq i -1 ents nil)
- (while (setq en (ssname ss (setq i (1+ i))))
- (setq pt (find-centerpoint en))
- (setq en1(list (car pt) (cadr pt) (cadr pt) en))
- (setq ents (cons en1 ents))
- )
- (setq ents (mapcar '(lambda (x) (nth 3 x)) (vl-sort (vl-sort ents '(lambda (a b) (< (car a) (car b)))) '(lambda (c d) (> (cadr c) (cadr d))))))
- (setq i 0)
- (mapcar '(lambda (x)
- (setq pt (find-centerpoint x))
- (entmakex
- (list '(0 . "text")
- (cons 1 (if (wcmatch write "Y") (strcat str (itoa (setq i (1+ i))))(itoa (setq i (1+ i)))))
- (cons 10 pt)
- (cons 62 3)
- (cons 40 200)
- (cons 11 pt)
- (cons 72 1)
- (cons 73 2)
- )
- )
- (setq pts (cons pt pts))
- )
- ents
- )
- )
- )
- )
- (defun find-centerpoint(en / po-li n y pc)
- (setq entda(entget en)
- ename(cdr(assoc 0 entda)))
- (if(= ename "CIRCLE")
- (setq pc(cdr(assoc 10 entda)))
- (progn
- (setq po-li (vl-remove-if 'not (mapcar '(lambda (x) (if (= (car x) 10) (cdr x))) entda)))
- (setq n(length po-li))
- (setq y(apply 'mapcar (cons '+ po-li)))
- (setq pc(mapcar '/ y (list n n n)))
- );progn
- );end if
- );end defun
|