Lisp lệnh HA trong chủ đề “Hỏi về Lisp (thuật toán, ý tưởng, coding,...)”
Viết giúp chú theo PA2 của anh Gia_bach (PA1 anh Gia_bach xét thiếu các đỉnh).
Không biết số ent màu hồng có nhiều không, chứ dùng PA command hơi ì ạch nếu số lượng đủ lớn.
(defun C:HA(/ old ent lst ds1 ds2) (command "undo" "be") (setq old (entlast)) (setq ent (car (entsel "\nChon Pline mau trang: "))) (princ "\nChon tat ca o vuong mau hong: ") (setq lst (#SS->List (ssget))) (mapcar '(lambda(e) (command "copy" e "" "none" '(0 0) "none" '(0 0)) (command "region" (entlast) "")) lst) (setq ds1 (GetNewEnts old) old (entlast)) (repeat (length lst) (command "copy" ent "" "none" '(0 0) "none" '(0 0)) (command "region" (entlast) "")) (setq ds2 (GetNewEnts old) i -1) (repeat (length ds1) (command "INTERSECT" (nth (setq i (1+ i)) ds1) (nth i ds2) "")) (command "undo" "e") (princ)) (defun GetNewEnts (ename / new) (while (setq ename (entnext ename)) (if (entget ename) (setq new (cons ename new)))) new) ; list ename (defun #SS->List (ss / i lst) (repeat (setq i (sslength ss)) (setq lst (cons (ssname ss (setq i (1- i))) lst))))
Tệp .lsp gốc không còn trên máy chủ. Hãy chép mã nguồn bên dưới (lấy từ bài viết gốc) vào một tệp văn bản, lưu với đuôi .lsp.
Cách dùng
- Chép mã nguồn, lưu thành tệp 428314_ha.lsp.
- 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 HA để chạy lisp.
Mã nguồn 428314_ha.lsp (trích từ bài viết gốc)
(defun C:HA(/ old ent lst ds1 ds2)
(command "undo" "be")
(setq old (entlast))
(setq ent (car (entsel "\nChon Pline mau trang: ")))
(princ "\nChon tat ca o vuong mau hong: ")
(setq lst (#SS->List (ssget)))
(mapcar '(lambda(e) (command "copy" e "" "none" '(0 0) "none" '(0 0)) (command "region" (entlast) "")) lst)
(setq ds1 (GetNewEnts old) old (entlast))
(repeat (length lst) (command "copy" ent "" "none" '(0 0) "none" '(0 0)) (command "region" (entlast) ""))
(setq ds2 (GetNewEnts old) i -1)
(repeat (length ds1)
(command "INTERSECT" (nth (setq i (1+ i)) ds1) (nth i ds2) ""))
(command "undo" "e") (princ))
(defun GetNewEnts (ename / new) (while (setq ename (entnext ename)) (if (entget ename) (setq new (cons ename new)))) new) ; list ename
(defun #SS->List (ss / i lst) (repeat (setq i (sslength ss)) (setq lst (cons (ssname ss (setq i (1- i))) lst))))Thảo luận gốc
Lisp được chia sẻ trong chủ đề Hỏi về Lisp (thuật toán, ý tưởng, coding,...). Xem đúng bài viết #428314 để đọc hướng dẫn và trao đổi thêm.