Lisp lệnh SHOW trong chủ đề “Giao diện hộp thoại trong AutoLisp”
Kiểu này chuối lắm dùng file *.chm hoặc *.hlp hay hơn nhiềucode đây không biết có đúng ý bạn không?
Thuty.dcl:
(defun read-txt (filename / open_f line_r list-out file_read) (setq list-out nil) (if (/= (findfile filename) nil) (progn (setq file_read (open filename "r")) (while (/= nil (setq line_r (read-line file_read)) ) (setq list-out (append list-out (list line_r))) ) (close file_read) ) (princ) ) list-out ) ;;;;;;;;;;;;;;; ;==== Load and check dialog =========== ; dia_name : string (defun loadcl ( dia_name) (if (= -1 (setq dcl_id (load_dialog (strcat dia_name ".dcl")))) (progn (alert (strcat dia_name ".dcl" "not found") (setq dialogloaded nil) ) );p (setq dialogloaded 1) );f );defun ;;;;;;;;;;;========================= (defun c:show (/ fname l1 dcl_id dialogloaded) (setq fname (getfiled "chon file" "c:\\" "*" 16)); lựa chọn file ;(setq fname "c:\\abc\\abc.txt"); hoặc chỉ định file (if (and (/= fname nil) (> (loadcl "thuty") 0); load and check dialog ) (if (not (new_dialog "thuty" dcl_id)) (exit); Error (progn;else (start_list "doctxt") (mapcar' add_list (read-txt fname)) (end_list) (start_dialog) (done_dialog) (unload_dialog dcl_id) );p );if1 );if (princ) );defunHave fun
Thanks Pro đã viết cho e nhưng ko đúng với ý e lắm! Anh viết lại hộ e như thế này đc ko:
Sau khi gõ lệnh, sẽ hiện ra hôp thoại "Doc file txt" luôn, không phải chọn đường dẫn nữa, mà em thắc mác cái "dùng file *.chm hoặc *.hlp hay hơn nhiều" của bác nói?
- Tải lisp
- 14254_show.lsp
Cách dùng
- Tải tệp 14254_show.lsp về máy.
- 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 SHOW để chạy lisp.
Mã nguồn 14254_show.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/1793-giao-di%E1%BB%87n-h%E1%BB%99p-tho%E1%BA%A1i-trong-autolisp/
(defun read-txt (filename / open_f line_r list-out file_read)
(setq list-out nil)
(if (/= (findfile filename) nil)
(progn
(setq file_read (open filename "r"))
(while
(/= nil
(setq line_r (read-line file_read))
)
(setq list-out (append list-out (list line_r)))
)
(close file_read)
)
(princ)
)
list-out
)
;;;;;;;;;;;;;;;
;==== Load and check dialog ===========
; dia_name : string
(defun loadcl ( dia_name)
(if (= -1 (setq dcl_id (load_dialog (strcat dia_name ".dcl"))))
(progn
(alert (strcat dia_name ".dcl" "not found")
(setq dialogloaded nil)
)
);p
(setq dialogloaded 1)
);f
);defun
;;;;;;;;;;;=========================
(defun c:show (/ fname l1 dcl_id dialogloaded)
(setq fname (getfiled "chon file" "c:\\" "*" 16)); lựa chọn file
;(setq fname "c:\\abc\\abc.txt"); hoặc chỉ định file
(if (and
(/= fname nil)
(> (loadcl "thuty") 0); load and check dialog
)
(if (not (new_dialog "thuty" dcl_id))
(exit); Error
(progn;else
(start_list "doctxt")
(mapcar' add_list (read-txt fname))
(end_list)
(start_dialog)
(done_dialog)
(unload_dialog dcl_id)
);p
);if1
);if
(princ)
);defun
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 #14254 để đọc hướng dẫn và trao đổi thêm.