Lisp lệnh DF trong chủ đề “SỬA GIÚP MÌNH LISP DÙNG HỘP THOẠI DIALOG?”
(defun c:df ( / dcl_code dcl_id file_dcl temp) (if (not *canopy*) (setq *canopy* (list "1" "0" "0" "0" "0" "0"))) (setq dcl_code (list (strcat "canopy : dialog { label = \"&Lisp ve canopy\";" " : boxed_radio_row { label = \"Select drawing type\"; key = \"dt\";" " : radio_button { label = \"&Side elevation\"; key = \"se\";}" " : radio_button { label = \"&Front elevation\"; key = \"fe\";}" " : radio_button { label = \"&plan\"; key = \"pl\";}}" " : column {" " : edit_box { label = \"Roof slope (%)\"; edit_width = 6; key = \"slope\";}" " : edit_box { label = \"Canopy length\"; edit_width = 6; key = \"length\";}" " : edit_box { label = \"Canopy width\"; edit_width = 6; key = \"width\";}}" " ok_cancel;}"))) (setq temp (vl-filename-mktemp "canopy.dcl") file_dcl (open temp "W")) (foreach l dcl_code (write-line l file_dcl)) (close file_dcl) (setq dcl_id (load_dialog temp)) (vl-file-delete temp) (new_dialog "canopy" dcl_id) (mapcar 'set_tile (list "se" "fe" "pl" "slope" "length" "width") canopy) (cond ((= (car *canopy*) "1") (mapcar 'mode_tile '("slope" "length" "width") '(0 1 0))) ((= (cadr *canopy*) "1") (mapcar 'mode_tile '("slope" "length" "width") '(0 0 1))) ((= (caddr *canopy*) "1") (mapcar 'mode_tile '("slope" "length" "width") '(1 0 0)))) (action_tile "se" "(mapcar 'mode_tile '(\"slope\" \"length\" \"width\") '(0 1 0))") (action_tile "fe" "(mapcar 'mode_tile '(\"slope\" \"length\" \"width\") '(0 0 1))") (action_tile "pl" "(mapcar 'mode_tile '(\"slope\" \"length\" \"width\") '(1 0 0))") (action_tile "accept" "(setq *canopy* (mapcar 'get_tile '(\"se\" \"fe\" \"pl\" \"slope\" \"length\" \"width\"))) (done_dialog)") (start_dialog) (unload_dialog dcl_id) (cond ((= (car *canopy*) "1") (alert "Viet code ve mat cat vao day")) ((= (cadr *canopy*) "1") (alert "Viet code ve mat dung vao day")) ((= (caddr *canopy*) "1") (alert "Viet code ve mat bang vao day"))) (princ))
Đây bạn. Viết hết luôn cho rồi nhé. Nhúng luôn DCL vào lisp luôn. mình toàn viết thế. test các hàm điều khiển DCL tiện hơn.
- Tải lisp
- 422318_df.lsp
Cách dùng
- Tải tệp 422318_df.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 DF để chạy lisp.
Mã nguồn 422318_df.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/170843-s%E1%BB%ADa-gi%C3%BAp-m%C3%ACnh-lisp-d%C3%B9ng-h%E1%BB%99p-tho%E1%BA%A1i-dialog/
(defun c:df ( / dcl_code dcl_id file_dcl temp)
(if (not *canopy*) (setq *canopy* (list "1" "0" "0" "0" "0" "0")))
(setq dcl_code (list (strcat
"canopy : dialog { label = \"&Lisp ve canopy\";"
" : boxed_radio_row { label = \"Select drawing type\"; key = \"dt\";"
" : radio_button { label = \"&Side elevation\"; key = \"se\";}"
" : radio_button { label = \"&Front elevation\"; key = \"fe\";}"
" : radio_button { label = \"&plan\"; key = \"pl\";}}"
" : column {"
" : edit_box { label = \"Roof slope (%)\"; edit_width = 6; key = \"slope\";}"
" : edit_box { label = \"Canopy length\"; edit_width = 6; key = \"length\";}"
" : edit_box { label = \"Canopy width\"; edit_width = 6; key = \"width\";}}"
" ok_cancel;}")))
(setq temp (vl-filename-mktemp "canopy.dcl") file_dcl (open temp "W"))
(foreach l dcl_code (write-line l file_dcl))
(close file_dcl)
(setq dcl_id (load_dialog temp))
(vl-file-delete temp)
(new_dialog "canopy" dcl_id)
(mapcar 'set_tile (list "se" "fe" "pl" "slope" "length" "width") canopy)
(cond ((= (car *canopy*) "1") (mapcar 'mode_tile '("slope" "length" "width") '(0 1 0)))
((= (cadr *canopy*) "1") (mapcar 'mode_tile '("slope" "length" "width") '(0 0 1)))
((= (caddr *canopy*) "1") (mapcar 'mode_tile '("slope" "length" "width") '(1 0 0))))
(action_tile "se" "(mapcar 'mode_tile '(\"slope\" \"length\" \"width\") '(0 1 0))")
(action_tile "fe" "(mapcar 'mode_tile '(\"slope\" \"length\" \"width\") '(0 0 1))")
(action_tile "pl" "(mapcar 'mode_tile '(\"slope\" \"length\" \"width\") '(1 0 0))")
(action_tile "accept" "(setq *canopy* (mapcar 'get_tile '(\"se\" \"fe\" \"pl\" \"slope\" \"length\" \"width\"))) (done_dialog)")
(start_dialog) (unload_dialog dcl_id)
(cond ((= (car *canopy*) "1") (alert "Viet code ve mat cat vao day"))
((= (cadr *canopy*) "1") (alert "Viet code ve mat dung vao day"))
((= (caddr *canopy*) "1") (alert "Viet code ve mat bang vao day")))
(princ))Thảo luận gốc
Lisp được chia sẻ trong chủ đề SỬA GIÚP MÌNH LISP DÙNG HỘP THOẠI DIALOG?. Xem đúng bài viết #422318 để đọc hướng dẫn và trao đổi thêm.