Jump to content

Lisp lệnh GT trong chủ đề “Nhờ viết lisp đo khoảng cách và ghi ra text có sẵn”

(defun c:gt (/ p1 p2 txt etxt d str)
(setvar "cmdecho" 0)
(while (and (setq p1 (getpoint "\n Chon diem thu nhat"))
(setq p2 (getpoint p1 "\n Chon diem thu hai "))
(setq txt (car (entsel "\n Chon text can thay" ))))
(progn
(command "undo" "begin")
(setq d (distance p1 p2) etxt (entget txt))
(setq str (strcat "\n" (cdr(assoc 1 etxt)) " + " (rtos d 2 2) " = " (rtos (+ d (atof(cdr(assoc 1 etxt)))) 2 2)))
(entmod(subst(cons 1 (rtos (+ d (atof (cdr(assoc 1 etxt)))) 2 2)) (assoc 1 etxt) etxt))
(command "change" txt "" "p" "c" 1 "")
(command "undo" "end")
(princ str)
(princ)
)
)
(setvar "cmdecho" 1)
(princ)
)

bạn thử xem đứng ý bạn không

Cách dùng

  1. Tải tệp 264625_gt.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 GT để chạy lisp.

Mã nguồn 264625_gt.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/86787-nh%E1%BB%9D-vi%E1%BA%BFt-lisp-%C4%91o-kho%E1%BA%A3ng-c%C3%A1ch-v%C3%A0-ghi-ra-text-c%C3%B3-s%E1%BA%B5n/
(defun c:gt (/ p1 p2 txt etxt d str)(setvar "cmdecho" 0)(while (and (setq p1 (getpoint "\n Chon diem thu nhat"))(setq p2 (getpoint p1 "\n Chon diem thu hai "))(setq txt (car (entsel "\n Chon text can thay" ))))(progn(command "undo" "begin")(setq d (distance p1 p2) etxt (entget txt))(setq str (strcat "\n" (cdr(assoc 1 etxt)) " + " (rtos d 2 2) " = " (rtos (+ d (atof(cdr(assoc 1 etxt)))) 2 2)))(entmod(subst(cons 1 (rtos (+ d (atof (cdr(assoc 1 etxt)))) 2 2)) (assoc 1 etxt) etxt))(command "change" txt "" "p" "c" 1 "")(command "undo" "end")(princ str)(princ)))(setvar "cmdecho" 1)(princ))

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Nhờ viết lisp đo khoảng cách và ghi ra text có sẵn. Xem đúng bài viết #264625 để đọc hướng dẫn và trao đổi thêm.

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