这是你日常生活的一个模式。
- ;;********************
- ;;* *
- ;;* C:BlocksList.LSP *
- ;;* *
- ;;********************
- (defun C:BlocksList ( ; Command emulation; ( local variables
- / Option; User option for output of block quantities (or exit)
- C_layer ; Current layer's name con'd with its assoc key (
- Block_list ; List of block's table information
- Block_cons ; List of block's name con'd with 2 (its assoc key)
- Block_set ; Selection set of all blocks with given name (& on curr layer)
- Block_name ; Current block's name
- Block_srch ; Search criteria for finding/selecting blocks
- Count$ ; Quantity of selected blocks as a string value
- Pattern ; Wild Card match layer name
- ) ; Close defun's local variables list
- (cond ; Begin routine--get user input first
- ((initget "All Current Pattern eXit")) ; Initialize options for user input
- ((= "eXit"
- (setq
- Option (getkword
- (strcat "List ["
- "All occurrences/Current layer only/Pattern/eXit"
- "] <Current layer only>: "
- )
- )
- )
- )
- ) ; Default is do blocks on current layer
- (T
- (if (= Option "Pattern") ; Wild Card match
- (while (= (vl-string-trim " \t\n"
- (setq Pattern (getstring t "\nEnter Layer name pattern. "))) "")
- (prompt "\nYou must enter a layer name.")
- )
- )
- (textscr)
- (prompt
- "\nPlease wait...Counting block insertions...Found..."
- )
- (cond
- ((= Option "All"))
- ((= Option "Pattern")(setq C_layer (cons 8 Pattern)))
- ((setq C_layer (cons 8 (getvar "CLAYER"))))
- )
- (while ; Inform user processing is starting
- (setq Block_list (tblnext "BLOCK" (not Block_list)))
- (setq Block_cons (assoc 2 Block_list)
- Block_name (cdr Block_cons)
- Block_srch (cond ; Step through entire block name database
- ((= (ascii Block_name) 42) nil)
- ; Ignore anonymous blocks: "*..."
- ((= Option "All") (list Block_cons))
- (T (list Block_cons C_layer))
- )
- ) ; Limit to current layer if All not opted
- (cond ; Now output (ignores unused blocknames)
- ((and Block_srch (setq Block_set (ssget "X" Block_srch)))
- (setq Count$ (itoa (sslength Block_set)))
- (prompt
- (strcat "\n" ; Build prompt string--pretty-print qty
- (substr " " 1 (- 6 (strlen Count$)))
- Count$
- " "
- Block_name ; Output qty & block name to screen
- )
- )
- ) ; Close cond's only opt & prompt-strcat
- )
- ) ; Close processing while & its cond
- (or Count$ (prompt "\n**< None Found >**"))
- )
- ) ; Close main cond & its T option
- (princ) ; Quiet exit
- ) ; The END (close defun C:BlocksList)
- (C:BlocksList) ; Auto-call @ actual, not dummy, load
|