Jump to content

Lisp lệnh TT%C2%A0 trong chủ đề “Nhờ Sửa Lisp Copy Cộng Dồn Khoảng Cách”

Gửi bạn: (bổ sung => hoặc chọn text để ghi kết quả hoặc chèn text mới)

(defun c:TT  (/ ent kqua obj sobichia sobitru sochia sotru ss ent-l poi)
 (vl-load-com)
 (initget "1 2 3 4")
 (or phep_tinh (setq phep_tinh "1"))
 (setq phep_tinh (cond ((getkword (strcat "\nChon phep tinh [1+/2-/3*/4:] <" phep_tinh ">: ")))
                       (phep_tinh)))
 (cond ;; cong
       ((= phep_tinh "1")
        (prompt "\nChon text de cong:")
        (setq ss   (ssget '((0 . "*TEXT")))
              kqua 0)
        (while (and ss (> (sslength ss) 0))
         (setq kqua (+ kqua (atof (cdr (assoc 1 (entget (setq ent (ssname ss 0))))))))
         (ssdel ent ss)))
       ;;nhan
       ((= phep_tinh "3")
        (prompt "\nChon text de nhan:")
        (setq ss   (ssget '((0 . "*TEXT")))
              kqua 1)
        (while (and ss (> (sslength ss) 0))
         (setq kqua (* kqua (atof (cdr (assoc 1 (entget (setq ent (ssname ss 0))))))))
         (ssdel ent ss)))
       ;;tru
       ((= phep_tinh "2")
        (and (princ "\nChon so bi tru:")
             (setq sobitru (ssget "_+.:E:S" '((0 . "*TEXT"))))
             (setq sobitru (distof (cdr (assoc 1 (entget (setq ent (ssname sobitru 0)))))))
             (princ "\nChon so tru:")
             (setq sotru (ssget "_+.:E:S" '((0 . "*TEXT"))))
             (setq sotru (distof (cdr (assoc 1 (entget (setq ent (ssname sotru 0)))))))
             (setq kqua (- sobitru sotru))))
       ;;chia
       ((= phep_tinh "4")
        (and (princ "\nChon so bi chia:")
             (setq sobichia (ssget "_+.:E:S" '((0 . "*TEXT"))))
             (setq sobichia (distof (cdr (assoc 1 (entget (setq ent (ssname sobichia 0)))))))
             (princ "\nChon so chia:")
             (setq sochia (ssget "_+.:E:S" '((0 . "*TEXT"))))
             (setq sochia (distof (cdr (assoc 1 (entget (setq ent (ssname sochia 0)))))))
             (not (eq sochia 0))
             (setq kqua (/ sobichia sochia)))))
 (if (and (or ss (and sobitru sotru) (and sobichia sochia)) kqua)
  (progn (or ssle (setq ssle 0))
         (setq ssle (cond ((getint (strcat "\nSo so le <" (itoa ssle) ">: ")))
                          (ssle)))
         (princ (strcat "\nChon text de ghi ket qua [Enter->Insert Text] <" (rtos kqua 2 ssle) ">: "))
         (if (setq ss (ssget "_+.:E:S" '((0 . "*TEXT"))))
          (progn (setq obj (vlax-ename->vla-object (ssname ss 0)))
                 (vla-put-TextString obj (rtos kqua 2 ssle)))
          (and (setq poi (getpoint "\nDiem chen Text: "))
               (setq ent-l (vl-remove-if-not '(lambda (x) (member (car x) '(0 1 7 8 40 41 42 50 51 62 100))) (entget ent))
                     ent-l (append (subst (cons 1 (rtos kqua 2 ssle)) (assoc 1 ent-l) ent-l) (list (cons 10 poi))))
               (entmakex ent-l)))))
 (princ))

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 394759_tt%C2%A0.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 TT%C2%A0 để chạy lisp.

Mã nguồn 394759_tt%C2%A0.lsp (trích từ bài viết gốc)

(defun c:TT  (/ ent kqua obj sobichia sobitru sochia sotru ss ent-l poi)
 (vl-load-com)
 (initget "1 2 3 4")
 (or phep_tinh (setq phep_tinh "1"))
 (setq phep_tinh (cond ((getkword (strcat "\nChon phep tinh [1+/2-/3*/4:] <" phep_tinh ">: ")))
                       (phep_tinh)))
 (cond ;; cong
       ((= phep_tinh "1")
        (prompt "\nChon text de cong:")
        (setq ss   (ssget '((0 . "*TEXT")))
              kqua 0)
        (while (and ss (> (sslength ss) 0))
         (setq kqua (+ kqua (atof (cdr (assoc 1 (entget (setq ent (ssname ss 0))))))))
         (ssdel ent ss)))
       ;;nhan
       ((= phep_tinh "3")
        (prompt "\nChon text de nhan:")
        (setq ss   (ssget '((0 . "*TEXT")))
              kqua 1)
        (while (and ss (> (sslength ss) 0))
         (setq kqua (* kqua (atof (cdr (assoc 1 (entget (setq ent (ssname ss 0))))))))
         (ssdel ent ss)))
       ;;tru
       ((= phep_tinh "2")
        (and (princ "\nChon so bi tru:")
             (setq sobitru (ssget "_+.:E:S" '((0 . "*TEXT"))))
             (setq sobitru (distof (cdr (assoc 1 (entget (setq ent (ssname sobitru 0)))))))
             (princ "\nChon so tru:")
             (setq sotru (ssget "_+.:E:S" '((0 . "*TEXT"))))
             (setq sotru (distof (cdr (assoc 1 (entget (setq ent (ssname sotru 0)))))))
             (setq kqua (- sobitru sotru))))
       ;;chia
       ((= phep_tinh "4")
        (and (princ "\nChon so bi chia:")
             (setq sobichia (ssget "_+.:E:S" '((0 . "*TEXT"))))
             (setq sobichia (distof (cdr (assoc 1 (entget (setq ent (ssname sobichia 0)))))))
             (princ "\nChon so chia:")
             (setq sochia (ssget "_+.:E:S" '((0 . "*TEXT"))))
             (setq sochia (distof (cdr (assoc 1 (entget (setq ent (ssname sochia 0)))))))
             (not (eq sochia 0))
             (setq kqua (/ sobichia sochia)))))
 (if (and (or ss (and sobitru sotru) (and sobichia sochia)) kqua)
  (progn (or ssle (setq ssle 0))
         (setq ssle (cond ((getint (strcat "\nSo so le <" (itoa ssle) ">: ")))
                          (ssle)))
         (princ (strcat "\nChon text de ghi ket qua [Enter->Insert Text] <" (rtos kqua 2 ssle) ">: "))
         (if (setq ss (ssget "_+.:E:S" '((0 . "*TEXT"))))
          (progn (setq obj (vlax-ename->vla-object (ssname ss 0)))
                 (vla-put-TextString obj (rtos kqua 2 ssle)))
          (and (setq poi (getpoint "\nDiem chen Text: "))
               (setq ent-l (vl-remove-if-not '(lambda (x) (member (car x) '(0 1 7 8 40 41 42 50 51 62 100))) (entget ent))
                     ent-l (append (subst (cons 1 (rtos kqua 2 ssle)) (assoc 1 ent-l) ent-l) (list (cons 10 poi))))
               (entmakex ent-l)))))
 (princ))

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Nhờ Sửa Lisp Copy Cộng Dồn Khoảng Cách. Xem đúng bài viết #394759 để đọc hướng dẫn và trao đổi thêm.

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