Jump to content

Lisp lệnh NBPL trong chủ đề “Thêm node vào đường Pline”

Chào bác Meohoang,

Bác thử dùng cái này coi sao nhé.

Mình bổ sung thêm vào lisp để có thể sử dụng với các loại đường LINE, POLYLINE, và LWPOLYLINE bác ạ.

Thực ra cái đường 2Dpolyline như bác nêu chính là cái đường LWPOLYLINE mà mình đã làm trong cái lisp cũ. Tuy nhiên với POLYLINE tức là đường 3Dpolyline thì lisp không đúng nữa do với các POLYLINE này sau khi break nó sẽ tạo ra hai đối tượng hoàn toàn mới và cái đối tượng cũ (ename) bị mất đi. Vì thế cái lệnh Pedit của mình không còn đúng nữa.

Với các line cũng vậy break thì ngon nhưng khi pedit lại phải thay đổ cấu trúc lệnh mới được và sau khi pedit thì các LINE sẽ trở thành LWPOLYLINE.

Vì thế mình dùng thêm hàm điều kiện để pedit cho từng trường hợp cụ thể. Bác cứ xem thêm trong lisp sẽ hiểu cách mình làm.

Cách này tuy chưa gọn gàng lắm nhưng có thể dùng được bác ạ.

Mong bác dùng thử và cho ý kiến để mình rút kinh nghiệm nha.

(defun c:NBPL()
(vl-load-com)
(setq oldos (getvar "osmode"))
(setvar "osmode" 0)
(setq ss (car (entsel "\n Pick chon doi tuong : ")))
(Hli ss)
(setq po (getpoint "\n Chon diem cat : "))
;;;(setq ddau (vlax-curve-getstartPoint ss  ))
;;;(setq dcuoi (vlax-curve-getEndPoint ss ))
(if (= (cdr (assoc 0 (entget ss))) "POLYLINE")
(progn
(Command "break" ss po "@")
(setq ent (entlast))
(command "undo" "be")
(entdel ent )
(command "undo" "e")
(setq ss (entlast))
(command "undo" "1")
(Command "Pedit" ss "j" ent "" "")
(Hli (entlast))
(while po 
(setq po (getpoint "\n Chon diem cat tiep theo : "))
;;;(Command "select" ddau dcuoi "")
;;;(setq ss (ssget "P"))
(if (/= po nil)
(progn
(Command "break" ss po "@")
(setq ent (entlast))
(command "undo" "be")
(entdel ent)
(command "undo" "e")
(setq ss (entlast))
(command "undo" "1")
(Command "Pedit" ss "j" ent "" "")
;;;(sssetfirst ss ss)
(Hli ss)
)
)
)
)
)
(if (= (cdr (assoc 0 (entget ss))) "LWPOLYLINE")
(progn
(Command "break" ss po "@")
(setq ent (entlast))
(Command "Pedit" ss "j" ent "" "")
(Hli ss)
(while po 
(setq po (getpoint "\n Chon diem cat tiep theo : "))
(if (/= po nil)
(progn
(Command "break" ss po "@")
(setq ent (entlast))
(Command "Pedit" ss "j" ent "" "")
(Hli ss)
)
)
)
)
)
(if (= (cdr (assoc 0 (entget ss))) "LINE")
(progn
(Command "break" ss po "@")
(setq ent (entlast))
(Command "Pedit" ss "y" "j" ent "" "")
(setq ss (entlast))
(Hli ss)
(while po 
(setq po (getpoint "\n Chon diem cat tiep theo : "))
(if (/= po nil)
(progn
(Command "break" ss po "@")
(setq ent (entlast))
(Command "Pedit" ss "j" ent "" "")
(Hli ss)
)
)
)
)
)
(setvar "osmode" oldos)

(princ)
)
;
(defun HLI(ent)
(sssetfirst (ssadd ent (ssadd)) (ssadd ent (ssadd)))
) 

Chúc bác khỏe và vui.

 

PS: các loại đường khác như arc , cung elip và spline mình thấy hình như mọi người ít dùng nên cũng chưa nghiên cứu rõ lắm. Nếu bác xét thấy cần thiết thì mình sẽ thử cố tí nữa xem sao. Hề hề hề....

 

Lisp của Bác Bình rất hay. :cheers:

thaks bác .Đúng cái em đang cần.

PS: à.Em có 1 ý kiến nhỏ là có lẽ bác nên để chế độ Osnap để bắt điểm chèn.

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

  1. Chép mã nguồn, lưu thành tệp 93972_nbpl.lsp.
  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 NBPL để chạy lisp.

Mã nguồn 93972_nbpl.lsp (trích từ bài viết gốc)

(defun c:NBPL()
(vl-load-com)
(setq oldos (getvar "osmode"))
(setvar "osmode" 0)
(setq ss (car (entsel "\n Pick chon doi tuong : ")))
(Hli ss)
(setq po (getpoint "\n Chon diem cat : "))
;;;(setq ddau (vlax-curve-getstartPoint ss  ))
;;;(setq dcuoi (vlax-curve-getEndPoint ss ))
(if (= (cdr (assoc 0 (entget ss))) "POLYLINE")
(progn
(Command "break" ss po "@")
(setq ent (entlast))
(command "undo" "be")
(entdel ent )
(command "undo" "e")
(setq ss (entlast))
(command "undo" "1")
(Command "Pedit" ss "j" ent "" "")
(Hli (entlast))
(while po 
(setq po (getpoint "\n Chon diem cat tiep theo : "))
;;;(Command "select" ddau dcuoi "")
;;;(setq ss (ssget "P"))
(if (/= po nil)
(progn
(Command "break" ss po "@")
(setq ent (entlast))
(command "undo" "be")
(entdel ent)
(command "undo" "e")
(setq ss (entlast))
(command "undo" "1")
(Command "Pedit" ss "j" ent "" "")
;;;(sssetfirst ss ss)
(Hli ss)
)
)
)
)
)
(if (= (cdr (assoc 0 (entget ss))) "LWPOLYLINE")
(progn
(Command "break" ss po "@")
(setq ent (entlast))
(Command "Pedit" ss "j" ent "" "")
(Hli ss)
(while po 
(setq po (getpoint "\n Chon diem cat tiep theo : "))
(if (/= po nil)
(progn
(Command "break" ss po "@")
(setq ent (entlast))
(Command "Pedit" ss "j" ent "" "")
(Hli ss)
)
)
)
)
)
(if (= (cdr (assoc 0 (entget ss))) "LINE")
(progn
(Command "break" ss po "@")
(setq ent (entlast))
(Command "Pedit" ss "y" "j" ent "" "")
(setq ss (entlast))
(Hli ss)
(while po 
(setq po (getpoint "\n Chon diem cat tiep theo : "))
(if (/= po nil)
(progn
(Command "break" ss po "@")
(setq ent (entlast))
(Command "Pedit" ss "j" ent "" "")
(Hli ss)
)
)
)
)
)
(setvar "osmode" oldos)

(princ)
)
;
(defun HLI(ent)
(sssetfirst (ssadd ent (ssadd)) (ssadd ent (ssadd)))
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Thêm node vào đường Pline. Xem đúng bài viết #93972 để đọc hướng dẫn và trao đổi thêm.

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