CXDUPDELPuliziaVersione 1.0.0Provato in AutoCAD
Eliminare gli oggetti esattamente duplicati
Trova gli oggetti disegnati due volte uno sopra l'altro con proprietà identiche ed elimina le copie in più, lasciandone una per ciascuno.
Come si usa
- Digita CXDUPDEL.
- Seleziona degli oggetti oppure digita ALL per tutto il disegno.
- Il rapporto indica quanti duplicati sono stati rimossi.
Da sapere
- Gli oggetti devono coincidere in ogni proprietà, layer e colore compresi, per contare come duplicati.
Caricarlo in AutoCAD
- Salva il file dove preferisci.
- Digita APPLOAD, scegli il file e premi Carica.
- Digita il nome del comando: CXDUPDEL.
Per averlo a ogni avvio, aggiungilo alla Raccolta di avvio nella stessa finestra, oppure carica un'intera cartella in una volta con il caricatore facoltativo. Il caricatore facoltativo
Provato in AutoCAD (versione completa). Altri programmi che eseguono AutoLISP potrebbero funzionare, ma non sono stati provati.
Il codice
Testo semplice, niente di nascosto. Copialo in un file chiamato cxdupdel.lsp oppure scaricalo.
;;; ============================================================================
;;; CXDUPDEL - Delete exact duplicate objects
;;; Version 1.0.0
;;; CADXChange LISP tools - https://cadxchange.net/resources/lisp/cxdupdel
;;; 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
;;; ============================================================================
;; A string that is the same for two entities exactly when they are duplicates of each other: every data group
;; except the handle, owner and reactor groups, with numbers rounded to 6 decimals.
(defun cx:dup-signature (ed / out)
(foreach g ed
(if (not (member (car g) '(-1 -2 -3 5 102 105 330 331 360)))
(setq out (cons (strcat (itoa (car g)) "="
(cond ((= (type (cdr g)) 'STR) (cdr g))
((= (type (cdr g)) 'INT) (itoa (cdr g)))
((= (type (cdr g)) 'REAL) (rtos (cdr g) 2 6))
((= (type (cdr g)) 'LIST) (apply 'strcat (mapcar (function (lambda (v) (strcat (rtos v 2 6) ","))) (cdr g))))
(T "")))
out))))
(cx:join (reverse out) ";"))
;; Erase every entity in NAMES that has an exact duplicate earlier in the list. Returns how many were erased.
(defun cx:dup-run (names / rows prev n)
(setq n 0)
(setq rows (cx:sort (mapcar (function (lambda (e) (cons (cx:dup-signature (entget e)) e))) names)
(function (lambda (a b) (< (car a) (car b))))))
(foreach r rows
(if (and prev (= (car prev) (car r)))
(progn (entdel (cdr r)) (setq n (1+ n)))
(setq prev r)))
n)
(defun c:CXDUPDEL ( / *error* cx:sv ss n)
(setq *error* cx:err)
(if (setq ss (cx:pick "\nSelect objects (type ALL for the whole drawing): " nil))
(progn
(cx:start '(("CMDECHO" . 0)))
(setq n (cx:dup-run (cx:ss->list ss)))
(princ (strcat "\n" (itoa n) " duplicate object(s) deleted."))
(cx:end)))
(princ))
;;; ---- Shared helpers (used by the command above; identical in every CADXChange tool) ----
(defun cx:join (lst delim / out)
(setq out "")
(foreach s lst
(setq out (if (= out "") s (strcat out delim s))))
(if lst out ""))
;; Merge sort of LST with PRED (a function of two items that is true when the first goes first).
(defun cx:sort (lst pred / half a b out)
(cond
((or (null lst) (null (cdr lst))) lst)
(T
(setq half (/ (length lst) 2) a nil b lst)
(repeat half (setq a (cons (car b) a) b (cdr b)))
(setq a (cx:sort (reverse a) pred) b (cx:sort b pred) out nil)
(while (and a b)
(if (apply pred (list (car b) (car a)))
(setq out (cons (car b) out) b (cdr b))
(setq out (cons (car a) out) a (cdr a))))
(append (reverse out) a b))))
;; 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)
;; 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))
;; 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))
(princ "\nCXDUPDEL loaded. Type CXDUPDEL to start.")
(princ)
Cronologia delle versioni
Versione 1.0.0 · 27 ottobre 2026
Prima versione.
Altri comandi: Pulizia
CXBYLAYERRiportare colore, tipo di linea e spessore a DaLayerCXZEROLENTrovare ed eliminare linee e polilinee di lunghezza zeroCXEMPTYTXTTrovare ed eliminare i testi vuotiCXFONTCHKElencare gli stili di testo con il file del carattere mancanteCXFONTSUBSostituire un file di carattere con un altro in tutti gli stili di testoCXPURGERipulire il disegno finché non c'è più nulla da togliereCXDELTYPEEliminare tutti gli oggetti del tipo che scegliCXDIMRESETRiportare al valore misurato i testi di quota modificati a manoCXOBJCOUNTContare gli oggetti per tipo