多行文本编辑,明经上已经有很多带对话框的工具,楼主采用TXT文本编辑显得没有必要。
尽管如此还是简化下代码,仅供参考- ;;dwg->txt
- (defun c:xieru (/ ;| len |; i name ent pt en l_en ;| txt e1 e2 |; file_w)
- (setq ss (ssget (list (cons 0 "TEXT")))
- ;_ss (j_ssfilter ss 0 "TEXT")
- )
- ;;end set
- ;;(open "d://xiechu.txt" "w")
- (setq ;| len (sslength ss)|;
- i -1
- )
- ;;end set
- ;_ (repeat len ;_改用while循环,效率略高于repeat和foreach
- (while (setq name (ssname ss (setq i (1+ i))))
- (setq ;| name (ssname ss i)|;
- ent (entget name)
- pt (cdr (assoc 10 ent))
- en (cons (cdr (assoc 1 ent)) pt) ;_改用直接提取字符串,避免2多次使用entget
- l_en ;| (if en ;_空文字时选择不到的 |;
- (cons en l_en)
- ;| l_en)|;
- ;| ;_排序后置,避免每次加入1个文字重新排序
- l_en (vl-sort
- l_en
- (function
- (lambda (e1 e2) (< (cadr (cdr e1)) (cadr (cdr e2))))))
- i (1+ i)|;
- )
- ;;end set
- )
- ;;end repeat
- ;_(setq l_en (reverse l_en));_reverse失去意义,只需要排序倒置
- (setq l_en (vl-sort l_en (function (lambda (e1 e2) (> (caddr e1) (caddr e2)))))
- l (mapcar (function car) l_en)
- p_first (cdar l_en)
- ent (entget (caar l_en))
- zg (cdr (assoc 40 ent))
- tlay (cdr (assoc 8 ent))
- )
-
- ;|
- (setq i 0)
- (setq en (entget (car (nth i l_en))))
- (setq sty (cdr (assoc 7 en))
- zg (cdr (assoc 40 en))
- tlay (cdr (assoc 8 en))
- p_first (cdr (assoc 10 en))
- )|;
- ;;end set
- (setq file_w (open "d:\\CAD单行文字编辑.txt" "w"))
- ;| (repeat len
- (setq en (entget (car (nth i l_en))))
- (setq txt (cdr (assoc 1 en)))|;
- (while l
- (write-line (car l) file_w)
- ;(setq i (+ i 1))
- (setq l (cdr l))
- )
- ;;end repeat
- (close file_w)
- (startapp "C:\\Windows\\System32\\notepad.exe"
- "d:\\CAD单行文字编辑.txt")
- )
- ;;end fun
|