Jump to content

: Lisp chèn đối tượng theo lý trình


(defun c:lt(/ lst lt pt curve txtsiz msp i cen r tmp)
(grtext -1 "Free from Cadviet @Ketxu")
(command "undo" "be")
(vl-load-com)
(setq txtsiz (cond ((zerop (setq tmp (* (getvar "dimtxt")(getvar "dimscale")))) 1)
(T tmp))
msp (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
(mapcar 'set '(curve pt) (nentselp "\nPick start point:"))
(setq isFirst (< (distance (vlax-curve-getStartPoint curve) pt)(distance (vlax-curve-getEndPoint curve) pt)) i 0
ln (vlax-curve-getDistAtParam curve (vlax-curve-getEndParam curve ))
)
(while (and (setq lt (getreal (strcat "\nNhap ly trinh diem thu " (itoa (setq i (1+ i))) " : "))) (< lt ln))
(entmake
(list (cons 0 "CIRCLE")
(cons 10 (setq cen (vlax-curve-getPointAtDist curve (if isFirst lt (- ln lt)))))
(cons 40 (setq r 0.1)) ;Kich thuoc vong tron
)
)
(vla-addtext msp (strcat (itoa i) " " (rtos lt 2 2)) (vlax-3d-point (mapcar '+ cen (list 0 (* 2 r) 0))) txtsiz)
(setq lst (cons (cons i lt) lst))
)
(setq pt (getpoint "\nDiem dat bang thong ke:"))

(foreach e (reverse lst)
(vla-addtext msp (itoa (car e)) (vlax-3d-point pt) txtsiz)
(vla-addtext msp (rtos (cdr e) 2 2) (vlax-3d-point (polar pt 0 (* 5 txtsiz))) txtsiz )
(setq pt (polar pt (/ pi -2) (* 1.5 txtsiz)))
)
(command "undo" "en")
)

Cách dùng

  1. Tải tệp 192354_lt.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 LT để chạy lisp.

Mã nguồn 192354_lt.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/62370-y%C3%AAu-c%E1%BA%A7u-lisp-ch%C3%A8n-%C4%91%E1%BB%91i-t%C6%B0%E1%BB%A3ng-theo-l%C3%BD-tr%C3%ACnh/
(defun c:lt(/ lst lt pt curve txtsiz msp i cen r tmp)
(grtext -1 "Free from Cadviet @Ketxu")
(command "undo" "be")
(vl-load-com)
(setq  txtsiz (cond ((zerop (setq tmp (* (getvar "dimtxt")(getvar "dimscale")))) 1)
 	(T tmp))  
 msp (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))) 
(mapcar 'set '(curve pt) (nentselp "\nPick start point:"))
(setq isFirst (< (distance (vlax-curve-getStartPoint curve) pt)(distance (vlax-curve-getEndPoint curve) pt)) i 0
 ln (vlax-curve-getDistAtParam curve (vlax-curve-getEndParam curve ))
)
(while (and (setq lt (getreal (strcat "\nNhap ly trinh diem thu " (itoa (setq i (1+ i))) " : "))) (< lt ln))
 (entmake
  (list (cons 0 "CIRCLE")
 (cons 10  (setq cen (vlax-curve-getPointAtDist curve (if isFirst lt (- ln lt)))))
 (cons 40 (setq r 0.1)) ;Kich thuoc vong tron
  )
 )
 (vla-addtext msp (strcat (itoa i) " " (rtos lt 2 2)) (vlax-3d-point (mapcar '+ cen (list 0 (* 2 r) 0))) txtsiz)
 (setq lst (cons (cons i lt) lst))
)
(setq  pt (getpoint "\nDiem dat bang thong ke:"))

(foreach e (reverse lst)
(vla-addtext msp (itoa (car e)) (vlax-3d-point pt) txtsiz)
(vla-addtext msp (rtos (cdr e) 2 2) (vlax-3d-point (polar pt 0 (* 5 txtsiz))) txtsiz )
(setq pt (polar pt (/ pi -2) (* 1.5 txtsiz)))
)
(command "undo" "en")
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [ YÊU CẦU] : Lisp chèn đối tượng theo lý trình. Xem đúng bài viết #192354 để đọc hướng dẫn và trao đổi thêm.

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