CXTXTALIGNTestoVersione 1.0.0Provato in AutoCAD
Allineare i testi a un testo di riferimento
Sposta o ruota molti testi in modo che coincidano con un testo di riferimento: stesso bordo sinistro, stessa linea di base, stesso angolo o stessa altezza.
Come si usa
- Digita CXTXTALIGN e clicca il testo di riferimento.
- Seleziona i testi da regolare.
- Scegli Left, Baseline, Rotation o Height.
Da sapere
- Left e Baseline spostano soltanto i testi, non ne cambiano la dimensione.
Caricarlo in AutoCAD
- Salva il file dove preferisci.
- Digita APPLOAD, scegli il file e premi Carica.
- Digita il nome del comando: CXTXTALIGN.
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 cxtxtalign.lsp oppure scaricalo.
;;; ============================================================================
;;; CXTXTALIGN - Line up texts with a base text
;;; Version 1.0.0
;;; CADXChange LISP tools - https://cadxchange.net/resources/lisp/cxtxtalign
;;; 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
;;; ============================================================================
;; Line up the texts in NAMES with the text BASE.
;; MODE "Left" the insertion points get the X of BASE (a column of left edges)
;; MODE "Baseline" the insertion points get the Y of BASE (a row)
;; MODE "Rotation" the texts get the rotation of BASE
;; MODE "Height" the texts get the height of BASE
;; Returns how many texts were changed.
(defun cx:txtalign-run (base names mode / bed bp n ed p ang)
(setq bed (entget base) bp (cx:text-pt bed) n 0)
(foreach e names
(if (/= e base)
(progn
(setq ed (entget e) p (cx:text-pt ed))
(cond
((= mode "Left") (cx:move-text e (- (car bp) (car p)) 0.0))
((= mode "Baseline") (cx:move-text e 0.0 (- (cadr bp) (cadr p))))
((= mode "Height") (cx:upd e 40 (cx:dxf 40 bed)))
((= mode "Rotation")
(setq ang (cond ((and (= (cx:dxf 0 bed) "MTEXT") (cx:dxf 11 bed)) (atan (cadr (cx:dxf 11 bed)) (car (cx:dxf 11 bed))))
((cx:dxf 50 bed) (cx:dxf 50 bed))
(T 0.0)))
(if (= (cx:dxf 0 ed) "MTEXT")
(progn
(cx:upd e 11 (list (cos ang) (sin ang) 0.0))
(if (assoc 50 (entget e)) (cx:upd e 50 ang)))
(cx:upd e 50 ang))))
(setq n (1+ n)))))
n)
(defun c:CXTXTALIGN ( / *error* cx:sv r base ss mode)
(setq *error* cx:err)
(setq r (entsel "\nClick the text to line up with: "))
(if (and r (member (cx:dxf 0 (entget (car r))) '("TEXT" "MTEXT")))
(progn
(setq base (car r))
(if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
(progn
(setq mode (cx:ask-kw "Line up" "Left Baseline Rotation Height" "Left"))
(cx:start '(("CMDECHO" . 0)))
(princ (strcat "\n" (itoa (cx:txtalign-run base (cx:ss->list ss) mode)) " text(s) changed."))
(cx:end))))
(if r (princ "\nThat is not a text.")))
(princ))
;;; ---- Shared helpers (used by the command above; identical in every CADXChange tool) ----
(defun cx:dxf (code ed)
(cdr (assoc code ed)))
;; The point a TEXT, MTEXT or ATTRIB sits at (the alignment point when it is aligned).
(defun cx:text-pt (ed)
(if (and (member (cx:dxf 0 ed) '("TEXT" "ATTRIB" "ATTDEF"))
(or (/= 0 (cx:dxf 72 ed)) (/= 0 (cx:dxf 73 ed)))
(cx:dxf 11 ed))
(cx:dxf 11 ed)
(cx:dxf 10 ed)))
;; Move a text object by DX, DY (its insertion point and, for justified TEXT, its alignment point).
(defun cx:move-text (ename dx dy / ed p)
(setq ed (entget ename) p (cx:dxf 10 ed))
(setq ed (subst (list 10 (+ (car p) dx) (+ (cadr p) dy) (caddr p)) (assoc 10 ed) ed))
(if (and (/= (cx:dxf 0 ed) "MTEXT") (assoc 11 ed) (or (/= 0 (cx:dxf 72 ed)) (/= 0 (cx:dxf 73 ed))))
(progn
(setq p (cx:dxf 11 ed))
(setq ed (subst (list 11 (+ (car p) dx) (+ (cadr p) dy) (caddr p)) (assoc 11 ed) ed))))
(entmod ed)
(entupd ename))
;; 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))
;; 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))
;; 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 "\nCXTXTALIGN loaded. Type CXTXTALIGN to start.")
(princ)
Cronologia delle versioni
Versione 1.0.0 · 27 ottobre 2026
Prima versione.
Altri comandi: Testo
CXNUMNumerare i testi in sequenzaCXTXTADDAggiungere un prefisso o un suffisso a molti testiCXTXTCUTTagliare caratteri all'inizio o alla fine dei testiCXTXTCASECambiare maiuscole e minuscole di molti testiCXTXTREPLTrovare e sostituire in molti testi insiemeCXTXTCLEANPulire spazi e formattazione dei testiCXT2MUnire testi a riga singola in un unico testo multilineaCXM2TScomporre un testo multilinea in testi a riga singolaCXTXTSTYLECambiare stile e altezza di molti testiCXTXTCOUNTContare i testi identiciCXTXTSUMSommare i numeri contenuti nei testi