CADXChange

Alle LISP-Befehle

CXATTVISBlöcke und AttributeVersion 1.0.0In AutoCAD getestet

Blockattribute ein- oder ausblenden

Macht die Attribute vieler Blöcke in einem Schritt sichtbar oder unsichtbar, für ein bestimmtes oder für alle Attribute.

So verwenden Sie ihn

  1. CXATTVIS eingeben und die Blöcke wählen.
  2. Show oder Hide wählen.
  3. Den Attributnamen eingeben oder * für alle.

Gut zu wissen

  • Die Werte bleiben unverändert, nur die Darstellung ändert sich.

In AutoCAD laden

  1. Speichern Sie die Datei an einem beliebigen Ort.
  2. Geben Sie APPLOAD ein, wählen Sie die Datei und klicken Sie auf Laden.
  3. Geben Sie den Befehl ein: CXATTVIS.

Damit er bei jedem Start bereitsteht, fügen Sie ihn im selben Dialog zum Startup-Set hinzu, oder laden Sie mit dem optionalen Loader einen ganzen Ordner auf einmal. Der optionale Loader

In AutoCAD (Vollversion) getestet. Andere Programme, die AutoLISP ausführen, funktionieren vielleicht, wurden aber nicht getestet.

Der Code

Reiner Text, nichts ist versteckt. Kopieren Sie ihn in eine Datei namens cxattvis.lsp oder laden Sie ihn herunter.

;;; ============================================================================
;;; 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)

Versionsverlauf

Version 1.0.0 · 27. Oktober 2026

Erste Veröffentlichung.

Weitere Befehle: Blöcke und Attribute