Jump to content

Lisp lệnh LL2 trong chủ đề “[Nhờ Vả] Xin Sửa Giúp Lisp Dành Cho Vẽ Mũi Tên Dạng Leader Bằng Lwpolyline”

Thành quả cuối cùng, tạm sửa như vầy, mong mọi người tối ưu giùm vì nó còn khá nhiều bất tiện

(defun ve_PLine_q(/ lst_str p0 str)
(setq lst_str
(list
(cons "A" "Specify endpoint of arc or\n:")
(cons "L" "Specify next point or :")
(cons "H" "Specify starting/ending half-width ")
))
(setq p0 (getpoint "\nChon diem thu nhat"))
(setq str "Chon diem tiep theo")
(command "PLINE" p0
(while (> (getvar "cmdactive") 0)
(progn
(initget "A H L U W CE LC D C L R S")
(setq p0 (getpoint (getvar "lastpoint") (strcat "\n" str)))
(cond
((= (type p0) 'LIST) (command p0))
((= (type p0) 'STR)
(command p0)
(setq str (cdr (assoc p0 lst_str)))
)
((not p0) (command ""))
)
)
))
)



(defun c:ll2 (/ arr_leng arr_size el en_luu ls_10 ls_10_x1 ls_10_x2 ls_not10 r2)
(vl-load-com)
(setq arr_size 50.0 arr_leng 150.0 el (entlast))

(ve_PLine_q)
(if (and (/= el (entlast))
(setq en_luu (entget (entlast)))
(= (cdr(assoc 0 en_luu)) "LWPOLYLINE"))
(progn
;(alert "\nThuc hien chuyen doi")
(setq ls_10 (vl-remove-if '(lambda(x) (not(member (car x) '(10 40 41 42 91)))) en_luu)
ls_10_x1 (list (car ls_10) (cadr ls_10) (caddr ls_10) (cadddr ls_10) (car(cddddr ls_10)))
ls_10_x2 (cdr(cddddr ls_10))
ls_not10 (vl-remove-if '(lambda(x) (member (car x) '(5 330 -1 8 90 43 10 40 41 42 91))) en_luu))
(setq r2 (append
(subst (cons 41 arr_size) (assoc 41 ls_10_x1)ls_10_x1)
(list
(cons 10 (polar (cdr(car ls_10_x1)) (angle (cdr(car ls_10_x1)) (cdr(car ls_10_x2))) arr_leng))
(cons 40 0.0) (cons 41 0.0) (cons 42 0.0) (cons 91 0))
ls_10_x2))
(while (entnext el) (entdel (setq el (entnext el))))
(entmakex
(append
ls_not10
(list (cons 8 "0"))
(list (cons 90 (1+ (length ls_10))))
r2))
)
(princ "nothing do")
))

Cách dùng

  1. Tải tệp 400281_ll2.lsp về máy.
  2. 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ẽ.
  3. Gõ lệnh LL2 để chạy lisp.

Mã nguồn 400281_ll2.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/162685-nh%E1%BB%9D-v%E1%BA%A3-xin-s%E1%BB%ADa-gi%C3%BAp-lisp-d%C3%A0nh-cho-v%E1%BA%BD-m%C5%A9i-t%C3%AAn-d%E1%BA%A1ng-leader-b%E1%BA%B1ng-lwpolyline/
(defun ve_PLine_q(/ lst_str p0 str)(setq lst_str(list(cons "A" "Specify endpoint of arc or\n[Angle/CEnter/Direction/Halfwidth/Line/Radius/Second pt/Undo/Width]:")(cons "L" "Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:")(cons "H" "Specify starting/ending half-width ")))(setq p0 (getpoint "\nChon diem thu nhat"))(setq str "Chon diem tiep theo")(command "PLINE" p0(while (> (getvar "cmdactive") 0)(progn(initget "A H L U W CE LC D C L R S")(setq p0 (getpoint (getvar "lastpoint") (strcat "\n" str)))(cond((= (type p0) 'LIST) (command p0))((= (type p0) 'STR)(command p0)(setq str (cdr (assoc p0 lst_str))))((not p0) (command "")))))))(defun c:ll2 (/ arr_leng arr_size el en_luu ls_10 ls_10_x1 ls_10_x2 ls_not10 r2)(vl-load-com)(setq arr_size 50.0 arr_leng 150.0 el (entlast))(ve_PLine_q)(if (and (/= el (entlast))(setq en_luu (entget (entlast)))(= (cdr(assoc 0 en_luu)) "LWPOLYLINE"))(progn;(alert "\nThuc hien chuyen doi")(setq ls_10 (vl-remove-if '(lambda(x) (not(member (car x) '(10 40 41 42 91)))) en_luu)ls_10_x1 (list (car ls_10) (cadr ls_10) (caddr ls_10) (cadddr ls_10) (car(cddddr ls_10)))ls_10_x2 (cdr(cddddr ls_10))ls_not10 (vl-remove-if '(lambda(x) (member (car x) '(5 330 -1 8 90 43 10 40 41 42 91))) en_luu))(setq r2 (append(subst (cons 41 arr_size) (assoc 41 ls_10_x1)ls_10_x1)(list(cons 10 (polar (cdr(car ls_10_x1)) (angle (cdr(car ls_10_x1)) (cdr(car ls_10_x2))) arr_leng))(cons 40 0.0) (cons 41 0.0) (cons 42 0.0) (cons 91 0))ls_10_x2))(while (entnext el) (entdel (setq el (entnext el))))(entmakex(appendls_not10(list (cons 8 "0"))(list (cons 90 (1+ (length ls_10))))r2)))(princ "nothing do")))

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Nhờ Vả] Xin Sửa Giúp Lisp Dành Cho Vẽ Mũi Tên Dạng Leader Bằng Lwpolyline. Xem đúng bài viết #400281 để đọc hướng dẫn và trao đổi thêm.

Về Thư viện AutoLisp (trang 205)