Jump to content

Lisp thêm đỉnh cho PL

Mình cũng có 1 cái đây.

-Tên lệnh. TDPL:

-Chọn pline xong thì chọn các điểm muốn tạo thêm nút.

(Defun C:tdpl ( )   
(command "undo" "be")
(chonduong)
(chidienthem)
(taothemnut)
(while
(chidienthem)
(taothemnut)
)
(command "undo" "end")
(Princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(Defun chidienthem ( )  
 (setq luubatdiem (getvar "osmode")) 
 (setvar "osmode" 545)
(setq diemthem (getpoint "\nDiem muon tao nut tren duong dan:"))
(setq daidendiemthem (vlax-curve-getDistAtPoint doituongt diemthem))
(cond 
     ((= daidendiemthem nil) (princ "\nDiem chon khong thuoc doi tuong muon them, chon lai:") (chidienthem))
     ((/= daidendiemthem nil)
 )
 ) 
(setvar "osmode" luubatdiem)
(Princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(Defun chonduong ( )  
(Prompt "\nChon doi tuong duong muon them nut")
(setq doituong1 (entsel))
(while
(null doituong1)
(Prompt "\nChon doi tuong duong muon them nut")
(setq doituong1 (entsel))
)
(chonduongd)
(Princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(Defun chonduongd ( )  
(setq doituongt (car doituong1))
(setq doituong (entget doituongt))
(Princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(Defun taothemnut ( )  
 (setq luubatdiem (getvar "osmode"))
 (setvar "osmode" 0)
(setq sodinh (cdr (assoc 90 doituong)))
(setq Rec (acet-geom-vertex-list doituongt))
(setq ttd 0)
(setq daidendiemdinh (vlax-curve-getDistAtPoint doituongt (nth ttd Rec)))
(while (< daidendiemdinh daidendiemthem)
(setq ttd (1+ ttd))
(setq daidendiemdinh (vlax-curve-getDistAtPoint doituongt (nth ttd Rec)))
)
(command "pedit" doituongt "E")
(while (< 0 (getvar "CMDACTIVE")) 
(repeat (fix (fix (- ttd 1)))
(command "n"))
(command "I" diemthem "x" ""))
(setvar "osmode" luubatdiem)
(Princ)
(Princ)
)

 

*THeo mình xoi thì lisp của bác ket không ổn: ví dụ có pline có 2 phân đoạn khi mình chọn điểm muốn chèn nút ở phân đoạn thứ 2 thì pline mới sẽ thay đổi hình dáng do ko xét vị trí của nút muốn thêm so với các phân đoạn. Mà mình cũng ngạc nhiên là người yêu cầu lại thấy ổn khi dùng. :blush:

 

Cái của bá Duy hình như ko được đâu?

 

thử chưa?

Cách dùng

  1. Tải tệp 157408_tdpl.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 TDPL để chạy lisp.

Mã nguồn 157408_tdpl.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/47459-%C4%91%C3%A3-xong-lisp-th%C3%AAm-%C4%91%E1%BB%89nh-cho-pl/
(Defun C:tdpl ( )   
(command "undo" "be")
(chonduong)
(chidienthem)
(taothemnut)
(while
(chidienthem)
(taothemnut)
)
(command "undo" "end")
(Princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(Defun chidienthem ( )  
 (setq luubatdiem (getvar "osmode")) 
 (setvar "osmode" 545)
(setq diemthem (getpoint "\nDiem muon tao nut tren duong dan:"))
(setq daidendiemthem (vlax-curve-getDistAtPoint doituongt diemthem))
(cond 
     ((= daidendiemthem nil) (princ "\nDiem chon khong thuoc doi tuong muon them, chon lai:") (chidienthem))
     ((/= daidendiemthem nil)
 )
 ) 
(setvar "osmode" luubatdiem)
(Princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(Defun chonduong ( )  
(Prompt "\nChon doi tuong duong muon them nut")
(setq doituong1 (entsel))
(while
(null doituong1)
(Prompt "\nChon doi tuong duong muon them nut")
(setq doituong1 (entsel))
)
(chonduongd)
(Princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(Defun chonduongd ( )  
(setq doituongt (car doituong1))
(setq doituong (entget doituongt))
(Princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(Defun taothemnut ( )  
 (setq luubatdiem (getvar "osmode"))
 (setvar "osmode" 0)
(setq sodinh (cdr (assoc 90 doituong)))
(setq Rec (acet-geom-vertex-list doituongt))
(setq ttd 0)
(setq daidendiemdinh (vlax-curve-getDistAtPoint doituongt (nth ttd Rec)))
(while (< daidendiemdinh daidendiemthem)
(setq ttd (1+ ttd))
(setq daidendiemdinh (vlax-curve-getDistAtPoint doituongt (nth ttd Rec)))
)
(command "pedit" doituongt "E")
(while (< 0 (getvar "CMDACTIVE")) 
(repeat (fix (fix (- ttd 1)))
(command "n"))
(command "I" diemthem "x" ""))
(setvar "osmode" luubatdiem)
(Princ)
(Princ)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Đã xong] Lisp thêm đỉnh cho PL. Xem đúng bài viết #157408 để đọc hướng dẫn và trao đổi thêm.

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