CXPURGE整理バージョン 1.0.0AutoCAD で動作確認済み
何も消せなくなるまで図面を整理する
整理を繰り返し実行し、これ以上消せなくなるまで続けます。未使用の項目は別の未使用項目の中に隠れていることが多いからです。何が消えたかも報告されます。
使い方
- CXPURGE と入力します。
- 数回の整理が終わるのを待ちます。
- 削除されたブロック、画層、線種、スタイルの数を確認します。
知っておくこと
- 使用中のものは残ります。U で整理を取り消せます。
AutoCAD で読み込む
- ファイルを好きな場所に保存します。
- APPLOAD と入力し、ファイルを選んで「ロード」を押します。
- コマンド名を入力します:CXPURGE。
起動のたびに使うには、同じ画面で「スタートアップ スイート」に追加するか、任意のローダーでフォルダーごと読み込みます。 任意のローダーについて
AutoCAD(フル版)で動作確認しています。AutoLISP を実行できるほかのソフトでも動く場合がありますが、確認はしていません。
コード
隠している部分のないテキストです。cxpurge.lsp という名前のファイルにコピーするか、ダウンロードしてください。
;;; ============================================================================
;;; CXPURGE - Purge the drawing until nothing more goes
;;; Version 1.0.0
;;; CADXChange LISP tools - https://cadxchange.net/resources/lisp/cxpurge
;;; 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
;;; ============================================================================
;; How many entries the tables that PURGE touches hold: (blocks layers linetypes styles dimstyles).
(defun cx:purge-counts ( / out r)
(foreach tbl '("BLOCK" "LAYER" "LTYPE" "STYLE" "DIMSTYLE")
(setq r (tblnext tbl T) out (cons 0 out))
(while r
(setq out (cons (1+ (car out)) (cdr out)) r (tblnext tbl))))
(reverse out))
;; Purge unused blocks, layers, linetypes, styles and the like until nothing more goes. Nested definitions need
;; several rounds. Returns the entries removed per table, in the order of cx:purge-counts.
(defun cx:purge-run ( / before after)
(setq before (cx:purge-counts))
(repeat 4
(command "_.-PURGE" "_A" "*" "_N"))
(setq after (cx:purge-counts))
(mapcar '- before after))
(defun c:CXPURGE ( / *error* cx:sv r)
(setq *error* cx:err)
(cx:start '(("CMDECHO" . 0)))
(setq r (cx:purge-run))
(cx:end)
(princ (strcat "\nRemoved: " (itoa (nth 0 r)) " blocks, " (itoa (nth 1 r)) " layers, " (itoa (nth 2 r)) " linetypes, "
(itoa (nth 3 r)) " text styles, " (itoa (nth 4 r)) " dimension styles."))
(princ))
;;; ---- Shared helpers (used by the command above; identical in every CADXChange tool) ----
;; 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))
;; 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 "\nCXPURGE loaded. Type CXPURGE to start.")
(princ)
バージョン履歴
バージョン 1.0.0 · 2026年10月27日
最初のリリース。