您需要在编辑框的action\u tile语句中包含一个表达式,该语句将仅用与筛选器匹配的项目重新填充列表框。
以下是此类功能的示例:
- (defun c:test ( / d l )
-
- (while (setq d (tblnext "LAYER" (null d)))
- (setq l (cons (cdr (assoc 2 d)) l))
- )
- (_GetLayerSelection (acad_strlsort l))
- )
- (defun _GetLayerSelection ( layerlist / _PopulateListBox dch file layers return tmp )
- ;; Example by Lee Mac 2011 - www.lee-mac.com
- (defun _PopulateListBox ( key alist )
- (start_list key)
- (mapcar 'add_list alist)
- (end_list)
- alist
- )
- (cond
- (
- (not
- (and
- (setq file (open (setq tmp (vl-filename-mktemp nil nil ".dcl")) "w"))
- (write-line
- (strcat
- "layers : dialog { label = "Select Layer"; spacer;"
- " : list_box { key = "layers"; width = 50; fixed_width = true; height = 15; fixed_height = true; allow_accept = true; }"
- " : edit_box { key = "filter"; width = 50; fixed_width = true; value = "*"; label = "Filter:"; }"
- " spacer; ok_cancel;"
- "}"
- )
- file
- )
- (not (close file))
- (< 0 (setq dch (load_dialog tmp)))
- (new_dialog "layers" dch)
- )
- )
- )
- (
- t
- (_PopulateListBox "layers" (setq layers layerlist))
-
- (set_tile "layers" (setq return "0"))
- (set_tile "filter" "*")
- (action_tile "layers" "(setq return $value)")
- (action_tile "filter"
- (vl-prin1-to-string
- (quote
- (progn
- (setq filter (strcat "*" (strcase $value) "*"))
-
- (_PopulateListBox "layers"
- (setq layers
- (vl-remove-if-not '(lambda ( layer ) (wcmatch (strcase layer) filter)) layerlist)
- )
- )
-
- (set_tile "layers" (setq return (cond ( (< (atoi return) (length layers)) return ) ( "0" ))))
- )
- )
- )
- )
- (setq return (if (= 1 (start_dialog)) (nth (atoi return) layers)))
- )
- )
-
- (if (< 0 dch) (unload_dialog dch))
- (if (setq tmp (findfile tmp)) (vl-file-delete tmp))
- return
- )
|