Jump to content

Lisp tính lý trình các điểm trên 1 polyline/line


Hề hề hề,
Của bạn đây. Hy vọng bạn sẽ hài lòng với lần sửa này;

Chúc bạn luôn vui khi tham gia diễn đàn cùng mọi người.

Cách dùng

  1. Tải tệp 168189_glt.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 GLT để chạy lisp.

Mã nguồn 168189_glt.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/53192-y%C3%AAu-c%E1%BA%A7u-lisp-t%C3%ADnh-l%C3%BD-tr%C3%ACnh-c%C3%A1c-%C4%91i%E1%BB%83m-tr%C3%AAn-1-polylineline/

(defun c:glt (/ pl plst pa pd k l a lt lt1 lt2 txt tg etg txtp txtp1 txtp2 dl dl1 dl2)
(vl-load-com)
(command "undo" "be")
(setq pl (car (entsel "\n Chon polyline can ghi ly trinh")))
(setq plst (vl-sort (acet-geom-vertex-list pl) '(lambda (x y) (< (car x) (car y)))))
(setq pa (getstring t "\n Chon diem goc ghi ly trinh <T or P>: "))
(if (= (strcase pa) "T")
   (setq pd (car plst))
   (setq pd (last plst))
)
(setq k (getint "\n Chon so chu so thap phan: "))
(setq l (getint "\n Chon phuong an ghi ly trinh <1 or 2>: "))
(setq a (getpoint "\n Chon point can ghi ly trinh"))
(while ( /= a nil)
(if (= l 1)
   (progn
         (if (equal (vlax-curve-getStartPoint (setq obj (vlax-ename->vla-object pl))) pd 0.001)
             (setq lt (vlax-curve-getDistAtPoint obj (vlax-curve-getClosestPointTo obj a)))
             (setq lt (- (vlax-curve-getDistAtPoint obj (vlax-curve-getEndPoint obj)) 
                           (vlax-curve-getDistAtPoint obj (vlax-curve-getClosestPointTo obj a))))
         )
         (setq dl (- lt (* (fix (/ lt 1000)) 1000)))
         (if (< (fix dl) 100)
             (if (< (fix dl) 10)
                 (setq txtp (strcat "00" (rtos dl 2 k)))
                 (setq txtp (strcat "0" (rtos dl 2 k)))
             )
             (setq txtp (rtos dl 2 k))
         )
         (setq txt (strcat "Km" (itoa (fix (/ lt 1000))) "+" txtp))
         (setq tg (car (entsel "\n Chon text can thay the ")))
         (setq etg (entget tg))
         (setq etg (subst (cons 1 txt) (assoc 1 etg) etg))
         (entmod etg)
   )
   (progn
        (if (equal (vlax-curve-getStartPoint (setq obj (vlax-ename->vla-object pl))) pd 0.001)
            (progn
                 (setq lt1 (vlax-curve-getDistAtPoint obj (vlax-curve-getClosestPointTo obj a)))
                 (setq lt2 (vlax-curve-getDistAtPoint obj (vlax-curve-getClosestPointTo obj (getpoint "\n Chon second point can ghi ly trinh"))))
            )
            (progn
                (setq lt1 (- (vlax-curve-getDistAtPoint obj (vlax-curve-getEndPoint obj)) 
                                (vlax-curve-getDistAtPoint obj (vlax-curve-getClosestPointTo obj a))))
                (setq lt2 (- (vlax-curve-getDistAtPoint obj (vlax-curve-getEndPoint obj)) 
                                (vlax-curve-getDistAtPoint obj (vlax-curve-getClosestPointTo obj (getpoint "\n Chon second point can ghi ly trinh")))))
            )
         )
         (setq dl1 (- lt1 (* (fix (/ lt1 1000)) 1000)))
         (if (< (fix dl1) 100)
             (if (< (fix dl1) 10)
                 (setq txtp1 (strcat "00" (rtos dl1 2 k)))
                 (setq txtp1 (strcat "0" (rtos dl1 2 k)))
             )
             (setq txtp1 (rtos dl1 2 k))
         )
         (setq dl2 (- lt2 (* (fix (/ lt2 1000)) 1000)))
         (if (< (fix dl2) 100)
             (if (< (fix dl2) 10)
                 (setq txtp2 (strcat "00" (rtos dl2 2 k)))
                 (setq txtp2 (strcat "0" (rtos dl2 2 k)))
             )
             (setq txtp2 (rtos dl2 2 k))
         )
         (setq txt (strcat "Km" (itoa (fix (/ lt1 1000))) "+" txtp1 "-Km" (itoa (fix (/ lt2 1000))) "+" txtp2 ))
         (setq tg (car (entsel "\n Chon text can thay the ")))
         (setq etg (entget tg))
         (setq etg (subst (cons 1 txt) (assoc 1 etg) etg))
         (entmod etg)
    )
)
(setq a (getpoint "\n Ban hay chon diem tiep theo: "))
)
(command "undo" "e")
(princ)
) 

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Yêu cầu] Lisp tính lý trình các điểm trên 1 polyline/line. Xem đúng bài viết #168189 để đọc hướng dẫn và trao đổi thêm.

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