Jump to content

Lisp lệnh CONG trong chủ đề “Giao diện hộp thoại trong AutoLisp”

Đây là một ví dụ

File Lisp

(defun C:CONG()
(setq DCL_ID (load_dialog "CONG"))
(if (not (new_dialog "CONG" DCL_ID)) (exit))
(if (not a) (setq a "0.00"))
(set_tile "a" a)
(if (not B) (setq b "0.00"))
(set_tile "b" B)
(action_tile "a" "(setq a $value) (KIEM_TRA_LOI)")
(action_tile "b" "(setq b $value) (KIEM_TRA_LOI)")
(action_tile "cong" "(set_tile \"c\" (rtos (+ (distof (get_tile \"a\")) (distof (get_tile \"b\")))))")
(start_dialog)
(unload_dialog DCL_ID)
(princ))
(defun KIEM_TRA_LOI()
(set_tile "error" "")
(if
 (/= (type (distof a)) 'real)
 (progn
  (set_tile "error" "Cho em xin mot so thuc !")
  (mode_tile "a" 2)))
(if
 (/= (type (distof B)) 'real)
 (progn
  (set_tile "error" "Cho em xin mot con so !")
  (mode_tile "b" 2))))

File Dcl

CONG : dialog { label = "Cong 2 so";
 : boxed_row {
: edit_box { label = "a" ; key = "a" ; edit_width = 6; }
: edit_box { label = "b" ; key = "b" ; edit_width = 6; }
: edit_box { label = "c" ; key = "c" ; edit_width = 6; }
 }
 : boxed_row {
: button { label = "Cong" ; key = "cong"; }
: button { label = "Cancel" ; key = "cancel" ; is_default = true ; is_cancel = true; }
 }
 errtile;
}

Làm sao chạy được

mình down về bỏ vào 1 thư mục ở ổ C sau đó mở cad2008 load lisp vào

nhưng khi chạy nó báo lỗi nên chẳng thây gì cả

mong mọi người giúp đỡ.

mình đang tìm hiểu về nó

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 197826_cong.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 CONG để chạy lisp.

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

(defun C:CONG()
(setq DCL_ID (load_dialog "CONG"))
(if (not (new_dialog "CONG" DCL_ID)) (exit))
(if (not a) (setq a "0.00"))
(set_tile "a" a)
(if (not B) (setq b "0.00"))
(set_tile "b" B)
(action_tile "a" "(setq a $value) (KIEM_TRA_LOI)")
(action_tile "b" "(setq b $value) (KIEM_TRA_LOI)")
(action_tile "cong" "(set_tile \"c\" (rtos (+ (distof (get_tile \"a\")) (distof (get_tile \"b\")))))")
(start_dialog)
(unload_dialog DCL_ID)
(princ))
(defun KIEM_TRA_LOI()
(set_tile "error" "")
(if
 (/= (type (distof a)) 'real)
 (progn
  (set_tile "error" "Cho em xin mot so thuc !")
  (mode_tile "a" 2)))
(if
 (/= (type (distof B)) 'real)
 (progn
  (set_tile "error" "Cho em xin mot con so !")
  (mode_tile "b" 2))))

CONG : dialog { label = "Cong 2 so";
 : boxed_row {
: edit_box { label = "a" ; key = "a" ; edit_width = 6; }
: edit_box { label = "b" ; key = "b" ; edit_width = 6; }
: edit_box { label = "c" ; key = "c" ; edit_width = 6; }
 }
 : boxed_row {
: button { label = "Cong" ; key = "cong"; }
: button { label = "Cancel" ; key = "cancel" ; is_default = true ; is_cancel = true; }
 }
 errtile;
}

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Giao diện hộp thoại trong AutoLisp. Xem đúng bài viết #197826 để đọc hướng dẫn và trao đổi thêm.

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