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日
最初のリリース。