Jump to content

Lisp lệnh ICAL trong chủ đề “Tính toán trên cùng 1 textbox”

Dùng cái lisp này cũng được. Chỉ cần enter thôi, còn nhấn ok là thoát. Sau khi tính muốn dùng kết quả để tính tiếp thì cứ enter.

(defun c:ical (/ name file str id sup)
  (defun tinh(st / vt)
    (if (and st (/= st "") (not (vl-string-search "=" st)))
      (set_tile "cal" (strcat st "=" (rtos (cal st))))
      (if (setq vt (vl-string-search "=" st)) (set_tile "cal" (substr st (+ 2 vt)))))
  )
  (setq str 
  "ICAL : dialog {label = \"ICal\" ;
        : column {
        : row {
          : edit_box { key = \"cal\"; alignment = centered; edit_width = 50; value = \"\"; }
        }  ok_only ;
   }}  "
  )
 
  (setq file (open (setq name (strcat (substr (setq sup (vla-get-SupportPath (vla-get-Files
(vla-get-Preferences (vlax-get-acad-object))))) 1 (vl-string-search ";" sup)) "\\ICAL.DCL")) "w"))
  (write-line str file)
  (close file)
 
  (setq id (load_dialog name))
  (new_dialog "ICAL" id)  
  (action_tile "cal" "(tinh $value)")
  (action_tile "accept" "(done_dialog)")
  (mode_tile "cal" 2)
  (start_dialog)
  (if (< 0 id) (unload_dialog id))  
)
 
;;sqrt(2)*(3^7+4)-5+6*cos(30)/sin(60)-tang(45)*ln(2)

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 296311_ical.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 ICAL để chạy lisp.

Mã nguồn 296311_ical.lsp (trích từ bài viết gốc)

(defun c:ical (/ name file str id sup)
  (defun tinh(st / vt)
    (if (and st (/= st "") (not (vl-string-search "=" st)))
      (set_tile "cal" (strcat st "=" (rtos (cal st))))
      (if (setq vt (vl-string-search "=" st)) (set_tile "cal" (substr st (+ 2 vt)))))
  )
  (setq str 
  "ICAL : dialog {label = \"ICal\" ;
        : column {
        : row {
          : edit_box { key = \"cal\"; alignment = centered; edit_width = 50; value = \"\"; }
        }  ok_only ;
   }}  "
  )
 
  (setq file (open (setq name (strcat (substr (setq sup (vla-get-SupportPath (vla-get-Files
(vla-get-Preferences (vlax-get-acad-object))))) 1 (vl-string-search ";" sup)) "\\ICAL.DCL")) "w"))
  (write-line str file)
  (close file)
 
  (setq id (load_dialog name))
  (new_dialog "ICAL" id)  
  (action_tile "cal" "(tinh $value)")
  (action_tile "accept" "(done_dialog)")
  (mode_tile "cal" 2)
  (start_dialog)
  (if (< 0 id) (unload_dialog id))  
)
 
;;sqrt(2)*(3^7+4)-5+6*cos(30)/sin(60)-tang(45)*ln(2)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Tính toán trên cùng 1 textbox. Xem đúng bài viết #296311 để đọc hướng dẫn và trao đổi thêm.

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