Lisp lệnh QF trong chủ đề “Lisp Quick Filter: Lọc nhanh theo một số thuộc tính thông dụng”
22 giờ trước, vanlam6408 đã nói:vâng,mong là qf sẽ sớm được hoàn thiện nhất.hi
Đã chế lại màu lọc theo True Color (màu hiển thị). Bạn thử xem có lỗi gì k nhé!
;; List Box - Lee Mac ;; Displays a DCL list box allowing the user to make a selection from the supplied data. ;; msg - Dialog label ;; lst - List of strings to display ;; bit - 1=allow multiple; 2=return indexes ;; Returns: List of selected items/indexes, else nil (defun LM:listbox (msg lst bit / dch des tmp rtn) (cond ((not (and (setq tmp (vl-filename-mktemp nil nil ".dcl")) (setq des (open tmp "w")) (write-line (strcat "listbox:dialog{label=\"" msg "\";spacer;:list_box{key=\"list\";multiple_select=" (if (= 1 (logand 1 bit)) "true" "false" ) ";width=50;height=15;}spacer;ok_cancel;}" ) des ) (not (close des)) (< 0 (setq dch (load_dialog tmp))) (new_dialog "listbox" dch) ) ) (prompt "\nError Loading List Box Dialog.") ) (t (start_list "list") (foreach itm lst (add_list itm)) (end_list) (setq rtn (set_tile "list" "0")) (action_tile "list" "(setq rtn $value)") (setq rtn (if (= 1 (start_dialog)) (if (= 2 (logand 2 bit)) (mapcar '(lambda (x) (nth x lst)) (read (strcat "(" rtn ")")) ) (read (strcat "(" rtn ")")) ; (mapcar '(lambda ( x ) (nth x lst)) (read (strcat "(" rtn ")"))) ) ) ) ) ) (if (< 0 dch) (unload_dialog dch) ) (if (and tmp (setq tmp (findfile tmp))) (vl-file-delete tmp) ) rtn ) ;====================================Main Lisp: Quick Filter (QF) Update 19/08/2020 Loc theo "True Color"====================================== (defun C:QF (/ ss ss1 ob lyrname colr blkname txth txtn lstQF lstDCL lstidx lstfi a c d l ) (setq ss1 (entsel "\nSelect Object: ")) (while (or (null ss1) (= "" (cdr (assoc 0 (entget (car ss1))))) ) (setq ss1 (entsel "\nSelect Object Again: ")) ) (setq ss (entget (car ss1))) (setq ob (cdr (assoc 0 ss))) (setq lstQF (list (cons 0 ob))) (if (= "INSERT" ob) (setq lstDCL (list (strcat "Object : " "Block"))) (setq lstDCL (list (strcat "Object : " ob))) );endif (setq lyrname (cdr (assoc 8 ss))) (setq lstQF (append lstQF (list (cons 8 lyrname)))) (setq lstDCL (append lstDCL (list (strcat "Layer : " lyrname)) ) ) (setq c (cond ((cdr (assoc 62 ss))) ((abs (cdr (assoc 62 (tblsearch "LAYER" (cdr (assoc 8 ss))))) ) ) ) ) (while (setq d (tblnext "LAYER" (null d))) (if (= c (abs (cdr (assoc 62 d)))) (setq l (cons "," (cons (cdr (assoc 2 d)) l))) ) ) (setq lstQF (append lstQF (list "True Color"))) (setq lstDCL (append lstDCL (list (strcat "True Color : " (rtos c 2 0))) ) ) (if (= 2 (car (assoc 2 ss))) (progn (setq blkname (cdr (assoc 2 ss))) (setq lstQF (append lstQF (list (cons 2 blkname)))) (setq lstDCL (append lstDCL (list (strcat "Block Name : " blkname)) ) ) ) ;end progn ) ;end if (if (= 40 (car (assoc 40 ss))) (progn (setq txth (cdr (assoc 40 ss))) (setq lstQF (append lstQF (list (cons 40 txth)))) (setq lstDCL (append lstDCL (list (strcat "Text Height : " (rtos txth))) ) ) ) ;end progn ) ;end if (if (= 7 (car (assoc 7 ss))) (progn (setq txtn (cdr (assoc 7 ss))) (setq lstQF (append lstQF (list (cons 7 txtn)))) (setq lstDCL (append lstDCL (list (strcat "Text Style Name : " txtn)) ) ) );end progn );end if (setq lstidx (LM:listbox "Selection to Filter:" lstDCL 1)) (if lstidx (progn (foreach a lstidx (if (= "True Color" (nth a lstQF)) (if l (setq lstfi (append lstfi (list (cons -4 "<OR") (cons 62 c) (cons -4 "<AND") (cons 62 256) (cons 8 (apply 'strcat (cdr l))) (cons -4 "AND>") (cons -4 "OR>") ) )) (setq lstfi (append lstfi (list (cons 62 c)) )) ) (setq lstfi (append lstfi (list (nth a lstQF)))) ) ) (sssetfirst nil (ssget lstfi)) ) ) (Print "Write by: NghiaKieu") (princ) )
- Tải lisp
- 448803_qf.lsp
Cách dùng
- Tải tệp 448803_qf.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 QF để chạy lisp.
Mã nguồn 448803_qf.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/182351-lisp-quick-filter-l%E1%BB%8Dc-nhanh-theo-m%E1%BB%99t-s%E1%BB%91-thu%E1%BB%99c-t%C3%ADnh-th%C3%B4ng-d%E1%BB%A5ng/
;; List Box - Lee Mac
;; Displays a DCL list box allowing the user to make a selection from the supplied data.
;; msg - [str] Dialog label
;; lst - [lst] List of strings to display
;; bit - [int] 1=allow multiple; 2=return indexes
;; Returns: [lst] List of selected items/indexes, else nil
(defun LM:listbox (msg lst bit / dch des tmp rtn)
(cond
((not
(and
(setq tmp (vl-filename-mktemp nil nil ".dcl"))
(setq des (open tmp "w"))
(write-line
(strcat "listbox:dialog{label=\""
msg
"\";spacer;:list_box{key=\"list\";multiple_select="
(if (= 1 (logand 1 bit))
"true"
"false"
)
";width=50;height=15;}spacer;ok_cancel;}"
)
des
)
(not (close des))
(< 0 (setq dch (load_dialog tmp)))
(new_dialog "listbox" dch)
)
)
(prompt "\nError Loading List Box Dialog.")
)
(t
(start_list "list")
(foreach itm lst (add_list itm))
(end_list)
(setq rtn (set_tile "list" "0"))
(action_tile "list" "(setq rtn $value)")
(setq rtn
(if (= 1 (start_dialog))
(if (= 2 (logand 2 bit))
(mapcar '(lambda (x) (nth x lst))
(read (strcat "(" rtn ")"))
)
(read (strcat "(" rtn ")"))
; (mapcar '(lambda ( x ) (nth x lst)) (read (strcat "(" rtn ")")))
)
)
)
)
)
(if (< 0 dch)
(unload_dialog dch)
)
(if (and tmp (setq tmp (findfile tmp)))
(vl-file-delete tmp)
)
rtn
)
;====================================Main Lisp: Quick Filter (QF) Update 19/08/2020 Loc theo "True Color"======================================
(defun C:QF (/ ss ss1 ob lyrname colr blkname
txth txtn lstQF lstDCL lstidx lstfi a c
d l
)
(setq ss1 (entsel "\nSelect Object: "))
(while (or
(null ss1)
(= "" (cdr (assoc 0 (entget (car ss1)))))
)
(setq ss1 (entsel "\nSelect Object Again: "))
)
(setq ss (entget (car ss1)))
(setq ob (cdr (assoc 0 ss)))
(setq lstQF (list (cons 0 ob)))
(if (= "INSERT" ob)
(setq lstDCL (list (strcat "Object : " "Block")))
(setq lstDCL (list (strcat "Object : " ob)))
);endif
(setq lyrname (cdr (assoc 8 ss)))
(setq lstQF (append lstQF (list (cons 8 lyrname))))
(setq lstDCL (append lstDCL
(list (strcat "Layer : " lyrname))
)
)
(setq c
(cond
((cdr (assoc 62 ss)))
((abs (cdr (assoc 62 (tblsearch "LAYER" (cdr (assoc 8 ss)))))
)
)
)
)
(while (setq d (tblnext "LAYER" (null d)))
(if (= c (abs (cdr (assoc 62 d))))
(setq l (cons "," (cons (cdr (assoc 2 d)) l)))
)
)
(setq lstQF (append lstQF (list "True Color")))
(setq lstDCL (append lstDCL (list (strcat "True Color : " (rtos c 2 0))) ) )
(if (= 2 (car (assoc 2 ss)))
(progn
(setq blkname (cdr (assoc 2 ss)))
(setq lstQF (append lstQF (list (cons 2 blkname))))
(setq
lstDCL (append lstDCL
(list (strcat "Block Name : " blkname))
)
)
) ;end progn
) ;end if
(if (= 40 (car (assoc 40 ss)))
(progn
(setq txth (cdr (assoc 40 ss)))
(setq lstQF (append lstQF (list (cons 40 txth))))
(setq lstDCL
(append lstDCL
(list (strcat "Text Height : " (rtos txth)))
)
)
) ;end progn
) ;end if
(if (= 7 (car (assoc 7 ss)))
(progn
(setq txtn (cdr (assoc 7 ss)))
(setq lstQF (append lstQF (list (cons 7 txtn))))
(setq lstDCL (append lstDCL
(list (strcat "Text Style Name : " txtn))
)
)
);end progn
);end if
(setq lstidx (LM:listbox "Selection to Filter:" lstDCL 1))
(if lstidx
(progn
(foreach a lstidx
(if (= "True Color" (nth a lstQF))
(if l
(setq lstfi (append lstfi
(list
(cons -4 "<OR")
(cons 62 c)
(cons -4 "<AND")
(cons 62 256)
(cons 8 (apply 'strcat (cdr l)))
(cons -4 "AND>")
(cons -4 "OR>")
)
))
(setq lstfi (append lstfi
(list (cons 62 c))
))
)
(setq lstfi (append lstfi (list (nth a lstQF))))
)
)
(sssetfirst nil (ssget lstfi))
)
)
(Print "Write by: NghiaKieu")
(princ)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Lisp Quick Filter: Lọc nhanh theo một số thuộc tính thông dụng. Xem đúng bài viết #448803 để đọc hướng dẫn và trao đổi thêm.