Lisp lệnh VT trong chủ đề “Nhờ các pro sửa hộ em lisp này theo yêu cầu với ạ”
Hôm qua mạng chổ mình lỗi
Giờ mới thông, lỡ rồi, up lên cho loét luôn
Cách dùng tương tự Tot77:
;Lisp lam cho y/c nay:
;;https://www.cadviet.com/forum/topic/98661-nho-cac-pro-sua-ho-em-lisp-nay-theo-yeu-cau-voi-a/
(defun c:vt( / old VAR ent pt_lst pt1 txt base_pt y1 info t_inf chenh i h ss j lst_ygh text n)
(command "undo" "be")
(setq old (mapcar 'getvar (setq VAR '("osmode" "cmdecho" "AUNITS"))))
(mapcar 'setvar VAR '(0 0 1))
(while (not ent)
(prompt "\nChon polynie: ")
(setq ent (ssget "_+.:E:S" '((0 . "*POLYLINE"))))
)
(setq pt_lst (acet-geom-vertex-list (ssname ent 0)))
(setvar "osmode" 1)
(initget 1)
(setq pt1 (getpoint "\nChon diem bat dau polyline: "))
(cond
((not
(or (equal pt1 (car pt_lst) 0.01)
(equal pt1 (last pt_lst) 0.01)
)
)
(prompt "\nDiem chon khong thuoc polyline _ vui long lam lai tu dau !")
(mapcar 'setvar VAR old)
(exit)
)
((not (equal pt1 (car pt_lst) 0.01))
(setq pt_lst (reverse pt_lst)))
)
(setvar "osmode" 0)
(while (not txt)
(prompt "\nChon text cao do diem bat dau: ")
(setq txt (ssget "_+.:E:S" '((0 . "*TEXT"))))
)
(setq base_pt (cdr (assoc 10 (setq info (entget(ssname txt 0)))))
y1 (atof (cdr (assoc 1 info)))
chenh (- (cadr (car pt_lst)) y1)
i 0)
(while (< i (1- (length pt_lst)))
(setq h (- (cadr (nth (setq i (1+ i)) pt_lst)) chenh))
(command ".copy" txt "" base_pt (list (car (nth i pt_lst)) (cadr base_pt)))
(entmod (subst (cons 1 (rtos h 2 3)) (assoc 1 (setq t_inf (entget (entlast)))) t_inf))
)
(while (or (not ss) (/= 3 (sslength ss)))
(prompt "\nChon 3 duong gioi han: ")
(setq ss (ssget '((0 . "LINE"))))
)
(setq j 0)
(repeat 3
(setq lst_ygh (cons (caddr (assoc 10 (entget (ssname ss j)))) lst_ygh)
j (1+ j)
)
)
(setq lst_ygh (vl-sort lst_ygh '<))
(foreach pt (cdr pt_lst)
(entmake (list (cons 0 "LINE") (cons 10 pt) (list 11 (car pt) (last lst_ygh))))
(entmake (list (cons 0 "LINE") (list 10 (car pt) (cadr lst_ygh)) (list 11 (car pt) (car lst_ygh))))
)
(setq n 0)
(repeat (1- (length pt_lst))
(setq text (abs (- (car (nth (1+ n) pt_lst)) (car (nth n pt_lst)))))
(command ".text"
"s" (cdr (assoc 7 info))
"j" "MC"
(list (/ (+ (car (nth n pt_lst)) (car (nth (1+ n) pt_lst))) 2.0) (/ (+ (car lst_ygh) (cadr lst_ygh)) 2.0))
(cdr(assoc 40 info))
(if (< text (* 4 (cdr(assoc 40 info)))) 90 0)
(rtos text 2 3)
)
(setq n (1+ n))
)
(mapcar 'setvar VAR old)
(command "undo" "end")
(princ)
)
p/s: Chỉ là bài thực hành trong lúc chưa có bài học, mong đc chỉ giáo thêm !
:D :D :D
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 288193_vt.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 VT để chạy lisp.
Mã nguồn 288193_vt.lsp (trích từ bài viết gốc)
;Lisp lam cho y/c nay:
;;https://www.cadviet.com/forum/topic/98661-nho-cac-pro-sua-ho-em-lisp-nay-theo-yeu-cau-voi-a/
(defun c:vt( / old VAR ent pt_lst pt1 txt base_pt y1 info t_inf chenh i h ss j lst_ygh text n)
(command "undo" "be")
(setq old (mapcar 'getvar (setq VAR '("osmode" "cmdecho" "AUNITS"))))
(mapcar 'setvar VAR '(0 0 1))
(while (not ent)
(prompt "\nChon polynie: ")
(setq ent (ssget "_+.:E:S" '((0 . "*POLYLINE"))))
)
(setq pt_lst (acet-geom-vertex-list (ssname ent 0)))
(setvar "osmode" 1)
(initget 1)
(setq pt1 (getpoint "\nChon diem bat dau polyline: "))
(cond
((not
(or (equal pt1 (car pt_lst) 0.01)
(equal pt1 (last pt_lst) 0.01)
)
)
(prompt "\nDiem chon khong thuoc polyline _ vui long lam lai tu dau !")
(mapcar 'setvar VAR old)
(exit)
)
((not (equal pt1 (car pt_lst) 0.01))
(setq pt_lst (reverse pt_lst)))
)
(setvar "osmode" 0)
(while (not txt)
(prompt "\nChon text cao do diem bat dau: ")
(setq txt (ssget "_+.:E:S" '((0 . "*TEXT"))))
)
(setq base_pt (cdr (assoc 10 (setq info (entget(ssname txt 0)))))
y1 (atof (cdr (assoc 1 info)))
chenh (- (cadr (car pt_lst)) y1)
i 0)
(while (< i (1- (length pt_lst)))
(setq h (- (cadr (nth (setq i (1+ i)) pt_lst)) chenh))
(command ".copy" txt "" base_pt (list (car (nth i pt_lst)) (cadr base_pt)))
(entmod (subst (cons 1 (rtos h 2 3)) (assoc 1 (setq t_inf (entget (entlast)))) t_inf))
)
(while (or (not ss) (/= 3 (sslength ss)))
(prompt "\nChon 3 duong gioi han: ")
(setq ss (ssget '((0 . "LINE"))))
)
(setq j 0)
(repeat 3
(setq lst_ygh (cons (caddr (assoc 10 (entget (ssname ss j)))) lst_ygh)
j (1+ j)
)
)
(setq lst_ygh (vl-sort lst_ygh '<))
(foreach pt (cdr pt_lst)
(entmake (list (cons 0 "LINE") (cons 10 pt) (list 11 (car pt) (last lst_ygh))))
(entmake (list (cons 0 "LINE") (list 10 (car pt) (cadr lst_ygh)) (list 11 (car pt) (car lst_ygh))))
)
(setq n 0)
(repeat (1- (length pt_lst))
(setq text (abs (- (car (nth (1+ n) pt_lst)) (car (nth n pt_lst)))))
(command ".text"
"s" (cdr (assoc 7 info))
"j" "MC"
(list (/ (+ (car (nth n pt_lst)) (car (nth (1+ n) pt_lst))) 2.0) (/ (+ (car lst_ygh) (cadr lst_ygh)) 2.0))
(cdr(assoc 40 info))
(if (< text (* 4 (cdr(assoc 40 info)))) 90 0)
(rtos text 2 3)
)
(setq n (1+ n))
)
(mapcar 'setvar VAR old)
(command "undo" "end")
(princ)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Nhờ các pro sửa hộ em lisp này theo yêu cầu với ạ. Xem đúng bài viết #288193 để đọc hướng dẫn và trao đổi thêm.