Lisp lấy số liệu từ hộp thoại
Chào bạn !
Bạ thử đoạn code này xem. Kết quả ra 1 list cac giá trị đã chọn. Bạn có thể ghi ra text hoặc xử lý nó theo mong muốn.
Bạ thử đoạn code này xem. Kết quả ra 1 list cac giá trị đã chọn. Bạn có thể ghi ra text hoặc xử lý nó theo mong muố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
- Chép mã nguồn, lưu thành tệp 166827_ai.lsp.
- 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ẽ.
- Gõ lệnh AI để chạy lisp.
Mã nguồn 166827_ai.lsp (trích từ bài viết gốc)
(defun c:ai (/ id str pos data sublist key De Fl)
(defun set_list ()
(start_list "Wx")
(foreach x
(setq sublist
(vl-remove-if '(lambda (x) (/= (substr x 1 3) (strcat "W" $value "x"))) data)
)
(add_list x)
)
(end_list)
)
(defun set_value (/ subdata)
(if sublist
(progn
(setq key (nth (atoi (get_tile "Wx")) sublist))
(setq subdata (member key data))
(set_tile "Depth" (setq De (cadr subdata)))
(set_tile "Flange" (setq Fl (caddr subdata)))
(mode_tile "accept" 0)
)
(mode_tile "accept" 1)
)
)
(setq f (open "d:/data.txt" "r"))
(setq str (read-line f))
(close f)
(setq data (append))
(while
(setq pos (vl-string-position 32 str))
(setq data (append data (list (substr str 1 pos))))
(setq str (vl-string-trim " " (substr str (+ pos 1))))
)
(setq data (append data (list str)))
(setq id (load_dialog "cadvietlisp"))
(new_dialog "AISC" id)
(mode_tile "accept" 1)
(action_tile "W" "(set_list)(set_value)")
(action_tile "Wx" "(set_value)")
(setq sta (start_dialog))
(unload_dialog id)
(if (= sta 1) (vl-remove 'nil (list key De Fl)))
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Yêu cầu lisp] Lisp lấy số liệu từ hộp thoại. Xem đúng bài viết #166827 để đọc hướng dẫn và trao đổi thêm.