enthralled Posted December 17, 2021 Posted December 17, 2021 Hello, I have mtext objects containing Line names and Pegs between brackets. I need to add a line break before the open bracket "(" and make the second line smaller by x0.6. I don't know how to write Lisp, so I tried adding the mtext formatting codes using Find/Replace, but the codes are showing as text and not changing the appearance of the text. Any help appriciated. Thanks Quote
Emmanuel Delay Posted December 17, 2021 Posted December 17, 2021 Like this Command MBCH (abbreviation of your title, feel free to change this) ;; Split MText at a "(" character. Set the last part on a new line, and 60% smaller size ;; Mtext: adding a line Break and Changing text Height (defun c:mbch ( / mtexts i txt newTxt ent) ;; (setq mtexts (ssget "_x" (list (cons 410 "Model") (cons 0 "MTEXT") )) ) ;; All MText objects in Model (setq mtexts (ssget (list (cons 0 "MTEXT") )) ) ;; User selects MText objects ;; go through all found objects (setq i 0) (repeat (sslength mtexts) (setq txt (cdr (assoc 1 (entget (setq ent (ssname mtexts i)))))) (princ txt) ;; \\H0.60x means 60% text size ;; "\\P{" ... "}" means ... is on a next line ;; So substitute bracket by "\\P{\\H0.60x(" and add "}" at the end (setq newTxt (strcat (vl-string-subst "\\P{\\H0.60x(" "(" txt) "}")) (entmod (subst (cons 1 newTxt) (assoc 1 (entget ent)) (entget ent) )) (setq i (+ i 1)) ) (princ) ) 1 Quote
enthralled Posted December 17, 2021 Author Posted December 17, 2021 52 minutes ago, Emmanuel Delay said: Like this Command MBCH (abbreviation of your title, feel free to change this) ;; Split MText at a "(" character. Set the last part on a new line, and 60% smaller size ;; Mtext: adding a line Break and Changing text Height (defun c:mbch ( / mtexts i txt newTxt ent) ;; (setq mtexts (ssget "_x" (list (cons 410 "Model") (cons 0 "MTEXT") )) ) ;; All MText objects in Model (setq mtexts (ssget (list (cons 0 "MTEXT") )) ) ;; User selects MText objects ;; go through all found objects (setq i 0) (repeat (sslength mtexts) (setq txt (cdr (assoc 1 (entget (setq ent (ssname mtexts i)))))) (princ txt) ;; \\H0.60x means 60% text size ;; "\\P{" ... "}" means ... is on a next line ;; So substitute bracket by "\\P{\\H0.60x(" and add "}" at the end (setq newTxt (strcat (vl-string-subst "\\P{\\H0.60x(" "(" txt) "}")) (entmod (subst (cons 1 newTxt) (assoc 1 (entget ent)) (entget ent) )) (setq i (+ i 1)) ) (princ) ) This is perfect! Thank you 1 Quote
eldon Posted December 17, 2021 Posted December 17, 2021 If you change the default Mtext editor to something like NotePad or WordPad, you can put in the formatting codes. I would say that your example drawing showed what you could do already without any help. However, the bottom line seemed to be a bit closer, so I stacked the bottom line. Quote
crgonzo Posted January 25 Posted January 25 I have a query sort of related to this. My desire is to "see" a \\P\\P and start an action from that...like copy a block to the next line of text. The action needs to be automated for each \\P\\P until the end of the mtext block. Is this possible? Thanks for any help or ideas. Quote
Steven P Posted January 25 Posted January 25 It's odd how things happen in succession, how are you for modifying LISPs? See the last code in the link below from a couple of days ago, it takes out the \\P using LM:Str->LST code and then remakes the string using LM:lst->str code. If you change the delimitators from \\P to \\P\\P (P and p to capture either way) in str->lst and then in the lst->str use a delimitator \\P\\P and add in whatever block of text you want that should do. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.