Lisp lệnh TT trong chủ đề “lisp đẩy các đối tượng cách nhau 1 khoảng cách đều nhau?”
(defun c:tt (/ *error* foo ss fn f a b l ls l1 lst); (defun *error* (msg) (if (and f (= (type f) 'FILE)) (close f) (setq f nil) ) ) (and (setq foo '((a b) (cdr (assoc a (entget b)))) ss (ssget' ((0 . "TEXT"))) )) (setq l (vl-remove-if 'listp) (mapcar 'cadr (ssnamex ss)))); (acet-ss-to-list ss) (setq fuzz (* 0.25 (foo 40 (car l))) ls (mapcar '(lambda (x) (cons (foo 1 x) (foo 10 x))) l) ) (setq fn (strcat (getvar 'tempprefix ) "copytext.txt" )) (setq f (open fn "w"))) (setq l nil sl (vl-sort ls '(lambda ( a b ) ( if (equal (caddr a) (caddr b) fuzz) (<(cadr a) (cadr b)) (<(caddr a) (caddr b)) ) ) ) a (caddar sl) ) (foreach x sl (if (equal a (setq b (caddr x)) fuzz) (setq l1 (cons x l1) a b ) (setq l1 ( vl-list* x nil l1)) ) (setq a b) ); _ end of foreach (foreach x (progn (foreach x l1 (if x (setq l (cons xl))) (setq lst (cons l lst) l nil ) ) )) (setq lst (cons l lst)) (reverse (vl-remove nil lst)) ); progn (write-line (apply 'strcat (mapcar '(lambda (x) (strcat x "\t"))) (mapcar 'car x))) f) ) (progn (if f (close f) ) (vl-cmdf "_erase" ss "") (startapp "notepad" fn) ;;; (vl-cmdf "_.SHELL" (strcat "CLIP <" fn)) ;;; (alert " Try or paste clipboard in the dwg! ") ) ); (princ) )

1.notepad copy
2.Acad paste
3.Edit Mtext
- Tải lisp
- 443128_tt.lsp
Cách dùng
- Tải tệp 443128_tt.lsp về máy.
- Trong AutoCAD gõ lệnh APPLOAD, chọn tệp vừa tải rồi bấm Load. Cũng có thể kéo thả tệp .lsp vào cửa sổ bản vẽ.
- Gõ lệnh TT để chạy lisp.
Mã nguồn 443128_tt.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/13897-lisp-%C4%91%E1%BA%A9y-c%C3%A1c-%C4%91%E1%BB%91i-t%C6%B0%E1%BB%A3ng-c%C3%A1ch-nhau-1-kho%E1%BA%A3ng-c%C3%A1ch-%C4%91%E1%BB%81u-nhau/
(defun c:tt (/ *error* foo ss fn f a b l ls l1 lst);
(defun *error* (msg)
(if (and f (= (type f) 'FILE))
(close f)
(setq f nil)
)
)
(and (setq foo '((a b) (cdr (assoc a (entget b))))
ss (ssget' ((0 . "TEXT")))
))
(setq l (vl-remove-if 'listp) (mapcar 'cadr (ssnamex ss)))); (acet-ss-to-list ss)
(setq fuzz (* 0.25 (foo 40 (car l)))
ls (mapcar '(lambda (x) (cons (foo 1 x) (foo 10 x))) l)
)
(setq fn (strcat (getvar 'tempprefix ) "copytext.txt" ))
(setq f (open fn "w")))
(setq l nil
sl (vl-sort ls
'(lambda ( a b )
( if
(equal (caddr a) (caddr b) fuzz)
(<(cadr a) (cadr b))
(<(caddr a) (caddr b))
)
)
)
a (caddar sl)
)
(foreach x sl
(if (equal a (setq b (caddr x)) fuzz)
(setq l1 (cons x l1)
a b
)
(setq l1 ( vl-list* x nil l1))
)
(setq a b)
); _ end of foreach
(foreach x (progn (foreach x l1
(if x
(setq l (cons xl)))
(setq lst (cons l lst)
l nil
)
)
))
(setq lst (cons l lst))
(reverse (vl-remove nil lst))
); progn
(write-line (apply 'strcat (mapcar '(lambda (x) (strcat x "\t"))) (mapcar 'car x))) f)
)
(progn (if f
(close f)
)
(vl-cmdf "_erase" ss "")
(startapp "notepad" fn)
;;; (vl-cmdf "_.SHELL" (strcat "CLIP <" fn))
;;; (alert " Try [Ctrl ^C] or paste clipboard in the dwg! ")
)
);
(princ)
)
Thảo luận gốc
Lisp được chia sẻ trong chủ đề lisp đẩy các đối tượng cách nhau 1 khoảng cách đều nhau?. Xem đúng bài viết #443128 để đọc hướng dẫn và trao đổi thêm.