CXATTVISBlocks and attributesVersion 1.0.0Tested in AutoCAD
Show or hide block attributes
Makes the attributes of many blocks visible or invisible in one step, for one tag or all tags.
How to use it
- Type CXATTVIS and select the blocks.
- Choose Show or Hide.
- Enter the tag, or * for every attribute.
Good to know
- The attribute values are never changed, only whether they are drawn.
Load it in AutoCAD
- Save the file anywhere you like.
- Type APPLOAD, pick the file and choose Load.
- Type the command name: CXATTVIS.
To have it at every start, add it to the Startup Suite in the same dialog, or load a whole folder at once with the optional loader. About the optional loader
Tested in AutoCAD (full version). Other programs that run AutoLISP may work, but they are not tested.
The code
Plain text, nothing hidden. Copy it into a file named cxattvis.lsp, or download it.
;;; ============================================================================
;;; 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)
Version history
Version 1.0.0 · October 27, 2026
First release.
More commands: Blocks and attributes
CXATTFILLFill an attribute in many blocksCXATTNUMNumber a block attribute in sequenceCXATTCOPYCopy attribute values from one block to othersCXBLKCOUNTCount blocks by nameCXBLKREPLReplace blocks with another blockCXBLKRENRename blocks in bulkCXBLKXPExplode blocks but keep their attribute textCXBLKSELSelect blocks by name or attribute valueCXBLKATInsert a block at many places at once