CXTXTSTYLE문자버전 1.0.0AutoCAD에서 테스트함
문자 스타일과 높이 한꺼번에 바꾸기
선택한 모든 문자에 같은 문자 스타일을, 원하면 같은 높이까지 지정합니다. 글꼴이 뒤섞인 도면을 정리할 때 유용합니다.
사용 방법
- CXTXTSTYLE을 입력하고 문자를 선택합니다.
- 사용할 문자 스타일 이름을 입력합니다. 도면에 있는 스타일이 먼저 나열됩니다.
- 새 높이를 입력합니다. 0이면 높이를 그대로 둡니다.
알아 두세요
- 스타일이 없으면 아무것도 바뀌지 않습니다.
AutoCAD에서 불러오기
- 파일을 원하는 곳에 저장합니다.
- APPLOAD를 입력하고 파일을 선택한 뒤 '로드'를 누릅니다.
- 명령 이름을 입력합니다: CXTXTSTYLE.
시작할 때마다 쓰려면 같은 대화상자에서 '시작 그룹'에 추가하거나, 선택 사항인 로더로 폴더 전체를 한 번에 불러옵니다. 선택 사항인 로더에 대해
AutoCAD(정식 버전)에서 테스트했습니다. AutoLISP를 실행하는 다른 프로그램에서도 될 수 있지만 테스트하지 않았습니다.
코드
숨겨진 부분이 없는 일반 텍스트입니다. cxtxtstyle.lsp 이름의 파일에 복사하거나 내려받으세요.
;;; ============================================================================
;;; CXTXTSTYLE - Change the style and height of texts
;;; Version 1.0.0
;;; CADXChange LISP tools - https://cadxchange.net/resources/lisp/cxtxtstyle
;;; 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
;;; ============================================================================
;; Give the texts in NAMES the text style STYLE, and the height HEIGHT when it is above zero.
;; Returns how many texts were changed, or nil when the style does not exist.
(defun cx:txtstyle-run (names style height / n)
(if (tblsearch "STYLE" style)
(progn
(setq n 0)
(foreach e names
(cx:upd e 7 style)
(if (> height 0.0) (cx:upd e 40 height))
(setq n (1+ n)))
n)))
;; The names of the text styles in the drawing, for the prompt.
(defun cx:style-names (/ r out)
(setq r (tblnext "STYLE" T))
(while r
(if (/= (cx:dxf 2 r) "") (setq out (cons (cx:dxf 2 r) out)))
(setq r (tblnext "STYLE")))
(reverse out))
(defun c:CXTXTSTYLE ( / *error* cx:sv ss style height n)
(setq *error* cx:err)
(if (setq ss (cx:pick "\nSelect texts: " '((0 . "TEXT,MTEXT"))))
(progn
(princ (strcat "\nText styles: " (cx:join (cx:style-names) ", ")))
(setq style (cx:ask-str "Text style" (getvar "TEXTSTYLE"))
height (cx:ask-real "New text height (0 keeps the heights)" 0.0))
(cx:start '(("CMDECHO" . 0)))
(if (setq n (cx:txtstyle-run (cx:ss->list ss) style height))
(princ (strcat "\n" (itoa n) " text(s) changed."))
(princ (strcat "\nThere is no text style named " style ".")))
(cx:end)))
(princ))
;;; ---- Shared helpers (used by the command above; identical in every CADXChange tool) ----
;; 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))
(defun cx:dxf (code ed)
(cdr (assoc code ed)))
;; 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)
(defun cx:join (lst delim / out)
(setq out "")
(foreach s lst
(setq out (if (= out "") s (strcat out delim s))))
(if lst out ""))
;; 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)))
;; Real X as text with at most PREC decimals and no trailing zeros ("2.50" -> "2.5", "3.00" -> "3").
(defun cx:num (x prec / s)
(setq s (rtos x 2 prec))
(if (wcmatch s "*.*")
(progn
(while (= (substr s (strlen s)) "0") (setq s (substr s 1 (1- (strlen s)))))
(if (= (substr s (strlen s)) ".") (setq s (substr s 1 (1- (strlen s)))))))
(if (or (= s "-0") (= s "")) "0" s))
(defun cx:ask-real (msg def / v)
(setq v (getreal (strcat "\n" msg " <" (cx:num def 6) ">: ")))
(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 "\nCXTXTSTYLE loaded. Type CXTXTSTYLE to start.")
(princ)
버전 기록
버전 1.0.0 · 2026년 10월 27일
첫 번째 릴리스.
여러 도면에 한꺼번에 쓰고 싶으신가요?
TextSync는 폴더 안의 도면 전체에 이런 작업을 한 번에 처리합니다.
TextSync