Lisp lệnh SZ trong chủ đề “LISP CHUYỂN MÀU CÁC ĐỐI TƯỢNG GIỐNG NHAU VÀ KHÁC NHAU”
1 phút trước, Han Tinh đã nói:Thanks bạn nha! chúng không cùng tọa độ nha bạn, các text bị lệch nhau nha bạn
(vl-load-com) (defun c:sz (/ ss lst h xlist ent1 x1 ent2 x2 lst1 ent i j nb1 nb2 nb3 nb4 txt1 txt2 txt3 txt4 x y z) (prompt "\nQu\U+00E9t ch\U+1ECDn khu v\U+1EF1c ch\U+1EE9a Text") (setq ss (acet-ss-to-list (ssget (list (cons 0 "TEXT"))))) (mapcar ' (lambda (x) (setq ent (entget x)) (setq ent (subst (cons 73 2) (assoc 73 ent) ent)) (setq ent (subst (cons 72 0) (assoc 72 ent) ent)) (entmod ent)) ss) (setq lst (list) h (* 2.5 (cdr (assoc 40 (entget (nth 0 ss))))) xlist (list)) (mapcar '(lambda (ent1) (setq x1 (fix (/ (cadr (assoc 10 (entget ent1))) h))) (if (not (vl-position x1 xlist)) (progn (setq xlist (append xlist (list x1))) (setq lst1 (list)) (mapcar ' (lambda (ent2) (setq x2 (fix (/ (cadr (assoc 10 (entget ent2))) h))) (if (= x1 x2) (progn (setq lst1 (append lst1 (list ent2))) )) ) ss) (setq lst (append lst (list lst1))) )) ) ss) (if (and (= (length lst) 4) (= (length (nth 0 lst)) (length (nth 2 lst))) (= (length (nth 1 lst)) (length (nth 3 lst))) ) (progn (foreach ent ss (vla-put-color (vlax-ename->vla-object ent) 1)) (setq lst (vl-sort lst ' (lambda (x y) (< (cadr (assoc 10 (entget (nth 0 x)))) (cadr (assoc 10 (entget (nth 0 y)))))))) (mapcar '(lambda z) (setq z (vl-sort z '(lambda (x y) (> (caddr (assoc 10 (entget x))) (caddr (assoc 10 (entget y))))))) lst) (setq i 0) (while (setq nb1 (nth i (nth 0 lst))) (setq txt1 (cdr (assoc 1 (entget nb1)))) (setq nb2 (nth i (nth 1 lst)) txt2 (cdr (assoc 1 (entget nb2)))) (if (vl-string-search "x" txt2) (progn (setq txt2 (Substr txt2 (+ (strlen (vl-string-right-trim "1234567890" txt2)) 1)) ))) (setq i (1+ i)) (setq j 0) (while (setq nb3 (nth j (nth 2 lst))) (setq txt3 (cdr (assoc 1 (entget nb3)))) (setq nb4 (nth j (nth 3 lst)) txt4 (cdr (assoc 1 (entget nb4)))) (if (vl-string-search "x" txt4) (progn (setq txt4 (Substr txt4 (+ (strlen (vl-string-right-trim "1234567890" txt4)) 1)) ))) (setq j (1+ j)) (if (and (= txt1 txt3) (= txt2 txt4)) (progn (vla-put-color (vlax-ename->vla-object nb1) 2) (vla-put-color (vlax-ename->vla-object nb2) 2) (vla-put-color (vlax-ename->vla-object nb3) 2) (vla-put-color (vlax-ename->vla-object nb4) 2) ))) ) ) (alert "\nS\U+1ED1 c\U+1ED9t text kh\U+00F4ng \U+0111\U+00FAng ho\U+1EB7c s\U+1ED1 text t\U+01B0\U+01A1ng \U+1EE9ng v\U+1EDBi m\U+1ED7i c\U+1ED9t kh\U+00F4ng b\U+1EB1ng nhau!") ) (princ) )
Ở lisp này mình đã chỉnh kiểu text về Middle Left cho dễ nhìn, các điểm insertion không cách nhau quá xa thì oke
.gif.a400b887e444a120aa72bd4439e0e25c.gif)
- Tải lisp
- 436281_sz.lsp
Cách dùng
- Tải tệp 436281_sz.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 SZ để chạy lisp.
Mã nguồn 436281_sz.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/176166-lisp-chuy%E1%BB%83n-m%C3%A0u-c%C3%A1c-%C4%91%E1%BB%91i-t%C6%B0%E1%BB%A3ng-gi%E1%BB%91ng-nhau-v%C3%A0-kh%C3%A1c-nhau/
(vl-load-com)
(defun c:sz (/ ss lst h xlist ent1 x1 ent2 x2 lst1 ent i j nb1 nb2 nb3 nb4 txt1 txt2 txt3 txt4 x y z)
(prompt "\nQu\U+00E9t ch\U+1ECDn khu v\U+1EF1c ch\U+1EE9a Text")
(setq ss (acet-ss-to-list (ssget (list (cons 0 "TEXT")))))
(mapcar ' (lambda (x) (setq ent (entget x)) (setq ent (subst (cons 73 2) (assoc 73 ent) ent)) (setq ent (subst (cons 72 0) (assoc 72 ent) ent))
(entmod ent)) ss)
(setq lst (list)
h (* 2.5 (cdr (assoc 40 (entget (nth 0 ss)))))
xlist (list))
(mapcar '(lambda (ent1)
(setq x1 (fix (/ (cadr (assoc 10 (entget ent1))) h)))
(if (not (vl-position x1 xlist)) (progn
(setq xlist (append xlist (list x1)))
(setq lst1 (list))
(mapcar ' (lambda (ent2)
(setq x2 (fix (/ (cadr (assoc 10 (entget ent2))) h)))
(if (= x1 x2) (progn
(setq lst1 (append lst1 (list ent2)))
))
) ss)
(setq lst (append lst (list lst1)))
))
) ss)
(if (and (= (length lst) 4)
(= (length (nth 0 lst)) (length (nth 2 lst)))
(= (length (nth 1 lst)) (length (nth 3 lst))) )
(progn
(foreach ent ss
(vla-put-color (vlax-ename->vla-object ent) 1))
(setq lst (vl-sort lst ' (lambda (x y) (< (cadr (assoc 10 (entget (nth 0 x)))) (cadr (assoc 10 (entget (nth 0 y))))))))
(mapcar '(lambda (z) (setq z (vl-sort z '(lambda (x y) (> (caddr (assoc 10 (entget x))) (caddr (assoc 10 (entget y)))))))) lst)
(setq i 0)
(while (setq nb1 (nth i (nth 0 lst)))
(setq txt1 (cdr (assoc 1 (entget nb1))))
(setq nb2 (nth i (nth 1 lst))
txt2 (cdr (assoc 1 (entget nb2))))
(if (vl-string-search "x" txt2) (progn
(setq txt2 (Substr txt2 (+ (strlen (vl-string-right-trim "1234567890" txt2)) 1))
)))
(setq i (1+ i))
(setq j 0)
(while (setq nb3 (nth j (nth 2 lst)))
(setq txt3 (cdr (assoc 1 (entget nb3))))
(setq nb4 (nth j (nth 3 lst))
txt4 (cdr (assoc 1 (entget nb4))))
(if (vl-string-search "x" txt4) (progn
(setq txt4 (Substr txt4 (+ (strlen (vl-string-right-trim "1234567890" txt4)) 1))
)))
(setq j (1+ j))
(if (and (= txt1 txt3)
(= txt2 txt4)) (progn
(vla-put-color (vlax-ename->vla-object nb1) 2)
(vla-put-color (vlax-ename->vla-object nb2) 2)
(vla-put-color (vlax-ename->vla-object nb3) 2)
(vla-put-color (vlax-ename->vla-object nb4) 2)
)))
)
) (alert "\nS\U+1ED1 c\U+1ED9t text kh\U+00F4ng \U+0111\U+00FAng ho\U+1EB7c s\U+1ED1 text t\U+01B0\U+01A1ng \U+1EE9ng v\U+1EDBi m\U+1ED7i c\U+1ED9t kh\U+00F4ng b\U+1EB1ng nhau!")
)
(princ)
)
Thảo luận gốc
Lisp được chia sẻ trong chủ đề LISP CHUYỂN MÀU CÁC ĐỐI TƯỢNG GIỐNG NHAU VÀ KHÁC NHAU. Xem đúng bài viết #436281 để đọc hướng dẫn và trao đổi thêm.