Lisp lệnh SS%C2%A0 trong chủ đề “List Tất Cả Layer, Teststyle, Dimstyle Trong Bản Vẽ Hiện Hành”
Gửi bạn lsp đã sửa:
;;; GETSTYLE - SETSTYLE
(defun C:SS (/ dcl_id ddiag dim dsts fname lay lst lyrs sty table_dst table_lyr table_tst tsts)
(setvar "cmdecho" 0)
;;Get list of all Layer-Textstyle-Dimstyle
(vlax-for lyr (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
(setq table_lyr (cons (vla-get-name lyr) table_lyr)))
(vlax-for tst (vla-get-textstyles (vla-get-activedocument (vlax-get-acad-object)))
(setq table_tst (cons (vla-get-name tst) table_tst)))
(vlax-for dst (vla-get-dimstyles (vla-get-activedocument (vlax-get-acad-object)))
(setq table_dst (cons (vla-get-name dst) table_dst)))
;; Get-current style
(setq lst (mapcar 'getvar '("CLAYER" "TEXTSTYLE" "DIMSTYLE"))
lay (itoa (vl-position (car lst) table_lyr))
sty (itoa (vl-position (cadr lst) table_tst))
dim (itoa (vl-position (caddr lst) table_dst)))
;; Create Dialog
(create_dialog)
;; Load dialog
(if (not (new_dialog "getstyle" (setq dcl_id (load_dialog fname))))
(exit))
;;Layer
(set_tile "sel_lyr" lay)
(start_list "sel_lyr")
(mapcar 'add_list table_lyr)
(end_list)
;;Textstyles
(set_tile "sel_tst" sty)
(start_list "sel_tst")
(mapcar 'add_list table_tst)
(end_list)
;;Dimstyles
(set_tile "sel_dst" dim)
(start_list "sel_dst")
(mapcar 'add_list table_dst)
(end_list)
;;Action
(action_tile "accept" "(setq ddiag 2)(Assign_value)(done_dialog)")
(action_tile "cancel" "(setq ddiag 1)(done_dialog)")
(start_dialog)
(unload_dialog dcl_id)
(if (= ddiag 1)
(princ "\n Cancelled!"))
(if (= ddiag 2)
(progn (alert (strcat "\nYou Selected Layer: " lyrs ", Textstyle: " tsts ", Dimstyle: " dsts))))
;; Delete DCL
(vl-file-delete fname)
(princ))
;;;----------------
(defun Assign_value ()
(setq lyrs (nth (atoi (get_tile "sel_lyr")) table_lyr)
tsts (nth (atoi (get_tile "sel_tst")) table_tst)
dsts (nth (atoi (get_tile "sel_dst")) table_dst))
(mapcar 'setvar '("CLAYER" "TEXTSTYLE") (list lyrs tsts))
(vla-put-activeDimstyle (vla-get-ActiveDocument (vlax-get-acad-object))
(vla-item (vla-get-Dimstyles (vla-get-ActiveDocument (vlax-get-acad-object))) dsts)))
;;;----------------
(defun create_dialog (/ lst-dia fn)
(setq lst-dia (list "getstyle: dialog {" "label = \"Select Layer, Textstyle, Dimstyle\";"
": column { "
": popup_list {"
"key = \"sel_lyr\";
label = \"Select layer\";
}"
": popup_list {" "key = \"sel_tst\";
label = \"Select textstyle\";
}"
": popup_list {" "key = \"sel_dst\";
label = \"Select dimstyle\";
}" "}" "ok_cancel ;}"))
(setq fname (vl-filename-mktemp "getstyle.dcl")
fn (open fname "w"))
(foreach x lst-dia (write-line x fn))
(close fn))
1. Như trên.
2. Lỗi trong file của bạn: ở hàm Assign_value -> (get_tile key), key ở đây nằm phải trong "", xem lsp đã sửa.
3. DCL nằm trong file .lsp:
+ Nguyên tắc chung:
- dùng lsp tạo ra 1 file DCL nằm đâu đó trong máy mà Cad tự tìm đến được và load khi cần.
- dùng xong thì lsp xóa DCL đi.
+ Tham khảo: http://www.afralisp.net/dialog-control-language/tutorials/dcl-without-the-dcl-file-part-2.php
- Tải lisp
- 393227_ss%C2%A0.lsp
Cách dùng
- Tải tệp 393227_ss%C2%A0.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 SS%C2%A0 để chạy lisp.
Mã nguồn 393227_ss%C2%A0.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/158654-list-t%E1%BA%A5t-c%E1%BA%A3-layer-teststyle-dimstyle-trong-b%E1%BA%A3n-v%E1%BA%BD-hi%E1%BB%87n-h%C3%A0nh/
;;; GETSTYLE - SETSTYLE
(defun C:SS (/ dcl_id ddiag dim dsts fname lay lst lyrs sty table_dst table_lyr table_tst tsts)
(setvar "cmdecho" 0)
;;Get list of all Layer-Textstyle-Dimstyle
(vlax-for lyr (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
(setq table_lyr (cons (vla-get-name lyr) table_lyr)))
(vlax-for tst (vla-get-textstyles (vla-get-activedocument (vlax-get-acad-object)))
(setq table_tst (cons (vla-get-name tst) table_tst)))
(vlax-for dst (vla-get-dimstyles (vla-get-activedocument (vlax-get-acad-object)))
(setq table_dst (cons (vla-get-name dst) table_dst)))
;; Get-current style
(setq lst (mapcar 'getvar '("CLAYER" "TEXTSTYLE" "DIMSTYLE"))
lay (itoa (vl-position (car lst) table_lyr))
sty (itoa (vl-position (cadr lst) table_tst))
dim (itoa (vl-position (caddr lst) table_dst)))
;; Create Dialog
(create_dialog)
;; Load dialog
(if (not (new_dialog "getstyle" (setq dcl_id (load_dialog fname))))
(exit))
;;Layer
(set_tile "sel_lyr" lay)
(start_list "sel_lyr")
(mapcar 'add_list table_lyr)
(end_list)
;;Textstyles
(set_tile "sel_tst" sty)
(start_list "sel_tst")
(mapcar 'add_list table_tst)
(end_list)
;;Dimstyles
(set_tile "sel_dst" dim)
(start_list "sel_dst")
(mapcar 'add_list table_dst)
(end_list)
;;Action
(action_tile "accept" "(setq ddiag 2)(Assign_value)(done_dialog)")
(action_tile "cancel" "(setq ddiag 1)(done_dialog)")
(start_dialog)
(unload_dialog dcl_id)
(if (= ddiag 1)
(princ "\n Cancelled!"))
(if (= ddiag 2)
(progn (alert (strcat "\nYou Selected Layer: " lyrs ", Textstyle: " tsts ", Dimstyle: " dsts))))
;; Delete DCL
(vl-file-delete fname)
(princ))
;;;----------------
(defun Assign_value ()
(setq lyrs (nth (atoi (get_tile "sel_lyr")) table_lyr)
tsts (nth (atoi (get_tile "sel_tst")) table_tst)
dsts (nth (atoi (get_tile "sel_dst")) table_dst))
(mapcar 'setvar '("CLAYER" "TEXTSTYLE") (list lyrs tsts))
(vla-put-activeDimstyle (vla-get-ActiveDocument (vlax-get-acad-object))
(vla-item (vla-get-Dimstyles (vla-get-ActiveDocument (vlax-get-acad-object))) dsts)))
;;;----------------
(defun create_dialog (/ lst-dia fn)
(setq lst-dia (list "getstyle: dialog {" "label = \"Select Layer, Textstyle, Dimstyle\";"
": column { "
": popup_list {"
"key = \"sel_lyr\";
label = \"Select layer\";
}"
": popup_list {" "key = \"sel_tst\";
label = \"Select textstyle\";
}"
": popup_list {" "key = \"sel_dst\";
label = \"Select dimstyle\";
}" "}" "ok_cancel ;}"))
(setq fname (vl-filename-mktemp "getstyle.dcl")
fn (open fname "w"))
(foreach x lst-dia (write-line x fn))
(close fn))Thảo luận gốc
Lisp được chia sẻ trong chủ đề List Tất Cả Layer, Teststyle, Dimstyle Trong Bản Vẽ Hiện Hành. Xem đúng bài viết #393227 để đọc hướng dẫn và trao đổi thêm.