CXATTVIS블록과 속성버전 1.0.0AutoCAD에서 테스트함
블록 속성 표시·숨기기
많은 블록의 속성을 한 번에 보이게 하거나 숨깁니다. 특정 태그 하나 또는 전체를 대상으로 할 수 있습니다.
사용 방법
- CXATTVIS를 입력하고 블록을 선택합니다.
- Show 또는 Hide를 고릅니다.
- 태그를 입력합니다. 모든 속성은 *를 입력합니다.
알아 두세요
- 속성 값은 바뀌지 않고 화면에 그려지는지 여부만 바뀝니다.
AutoCAD에서 불러오기
- 파일을 원하는 곳에 저장합니다.
- APPLOAD를 입력하고 파일을 선택한 뒤 '로드'를 누릅니다.
- 명령 이름을 입력합니다: CXATTVIS.
시작할 때마다 쓰려면 같은 대화상자에서 '시작 그룹'에 추가하거나, 선택 사항인 로더로 폴더 전체를 한 번에 불러옵니다. 선택 사항인 로더에 대해
AutoCAD(정식 버전)에서 테스트했습니다. AutoLISP를 실행하는 다른 프로그램에서도 될 수 있지만 테스트하지 않았습니다.
코드
숨겨진 부분이 없는 일반 텍스트입니다. cxattvis.lsp 이름의 파일에 복사하거나 내려받으세요.
;;; ============================================================================
;;; CXATTVIS - Show or hide block attributes
;;; Version 1.0.0
;;; CADXChange LISP tools - https://cadxchange.net/resources/lisp/cxattvis
;;; Tested in: AutoCAD (full version). Other programs that run AutoLISP may work but are not tested.
;;; Copyright (c) CADXChange. Free for personal and commercial use; do not resell or
;;; republish it as a collection. Terms: https://cadxchange.net/legal/lisp-terms
;;; ============================================================================
;; Show or hide attributes of the block references in NAMES. TAG is a tag name or "*" for every attribute.
;; SHOW = T shows, nil hides. Returns how many attributes were changed.
(defun cx:attvis-run (names tag show / n flags)
(setq n 0)
(foreach e names
(foreach a (cx:attribs e)
(if (or (= tag "*") (= (strcase (cx:dxf 2 (entget a))) (strcase tag)))
(progn
(setq flags (cx:dxf 70 (entget a)))
(cx:upd a 70 (if show (boole 1 flags -2) (boole 7 flags 1)))
(setq n (1+ n)))))
(entupd e))
n)
(defun c:CXATTVIS ( / *error* cx:sv ss names tags tag act n)
(setq *error* cx:err)
(if (setq ss (cx:pick "\nSelect blocks with attributes: " '((0 . "INSERT") (66 . 1))))
(progn
(setq names (cx:ss->list ss)
tags (cx:tags names))
(princ (strcat "\nAttributes in the selection: " (cx:join tags ", ")))
(setq act (cx:ask-kw "Attributes" "Show Hide" "Hide")
tag (cx:ask-str "Attribute tag (* for all)" "*"))
(cx:start '(("CMDECHO" . 0)))
(setq n (cx:attvis-run names tag (= act "Show")))
(princ (strcat "\n" (itoa n) " attribute(s) " (if (= act "Show") "shown" "hidden") "."))
(cx:end)))
(princ))
;;; ---- Shared helpers (used by the command above; identical in every CADXChange tool) ----
(defun cx:dxf (code ed)
(cdr (assoc code ed)))
;; The ATTRIB entities of a block reference, in order.
(defun cx:attribs (ins / e out)
(setq e (entnext ins))
(while (and e (= (cx:dxf 0 (entget e)) "ATTRIB"))
(setq out (cons e out) e (entnext e)))
(reverse out))
;; Change one group of an entity: (cx:upd ename 8 "LAYER1"); the group is added when missing.
(defun cx:upd (ename code value / ed old)
(setq ed (entget ename) old (assoc code ed))
(entmod (if old (subst (cons code value) old ed) (append ed (list (cons code value)))))
(entupd ename))
;; Close the undo step and put the system variables back.
(defun cx:end ()
(foreach v cx:sv (setvar (car v) (cdr v)))
(command "_.UNDO" "_End")
(setq cx:sv nil)
(princ))
;; Error handler: restores everything, stays quiet on Esc.
(defun cx:err (msg)
(if (> (getvar "CMDACTIVE") 0) (command))
(cx:end)
(if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")))
(princ (strcat "\nError: " msg)))
(princ))
;; Use the objects already selected, or ask the user to select; FILTER is an ssget filter list or nil.
(defun cx:pick (msg filter / ss)
(setq ss (if filter (ssget "_I" filter) (ssget "_I")))
(if (null ss)
(progn
(princ msg)
(setq ss (if filter (ssget filter) (ssget)))))
ss)
;; Selection set to a list of entity names.
(defun cx:ss->list (ss / i out)
(setq i 0)
(if ss
(repeat (sslength ss)
(setq out (cons (ssname ss i) out)
i (1+ i))))
(reverse out))
;; The attribute tags found in a list of block references, each once, in order of appearance.
(defun cx:tags (names / out)
(foreach e names
(foreach a (cx:attribs e)
(if (not (member (strcase (cx:dxf 2 (entget a))) (mapcar 'strcase out)))
(setq out (append out (list (cx:dxf 2 (entget a))))))))
out)
(defun cx:join (lst delim / out)
(setq out "")
(foreach s lst
(setq out (if (= out "") s (strcat out delim s))))
(if lst out ""))
;; Replace every OLD in STR by NEW (case sensitive).
(defun cx:replace (str old new / n out pos)
(setq n (strlen old) out "" pos 1)
(if (= n 0)
str
(progn
(while (<= pos (1+ (- (strlen str) n)))
(if (= (substr str pos n) old)
(setq out (strcat out new) pos (+ pos n))
(setq out (strcat out (substr str pos 1)) pos (1+ pos))))
(strcat out (substr str pos)))))
;; Ask for one of the keywords in BITS ("Yes No"), default DEF; returns the keyword.
(defun cx:ask-kw (msg bits def / v)
(initget 0 bits)
(setq v (getkword (strcat "\n" msg " [" (cx:replace bits " " "/") "] <" def ">: ")))
(if v v def))
;; Ask for a string (spaces allowed) with a default; "-" means an empty string.
(defun cx:ask-str (msg def / v)
(setq v (getstring T (strcat "\n" msg " <" def ">: ")))
(cond ((= v "") def) ((= v "-") "") (T v)))
;; Save the system variables in VARS ((name . value) ...), set them, and open one undo step.
;; The caller declares cx:sv as a local so the saved values live exactly as long as the command.
(defun cx:start (vars)
(setq cx:sv (mapcar (function (lambda (v) (cons (car v) (getvar (car v))))) vars))
(command "_.UNDO" "_Begin")
(foreach v vars (setvar (car v) (cdr v)))
(princ))
(princ "\nCXATTVIS loaded. Type CXATTVIS to start.")
(princ)
버전 기록
버전 1.0.0 · 2026년 10월 27일
첫 번째 릴리스.