Jump to content

Mtext: adding a line break and changing text height


Recommended Posts

Posted

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

image.thumb.png.84ea2262429c802334d14d378fa56ea3.png

Posted

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)
)

 

  • Like 1
Posted
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

  • Like 1
Posted

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.

 

 

1407622029_Moreformatting.thumb.PNG.85775c2bd837aaae6918cd5c12b63651.PNG

  • 2 years later...
Posted

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?

 

image.thumb.png.53fc9a886fda3616bd1392d67263bf5e.png

 

Thanks for any help or ideas.

Posted

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.

 

 

 

 

 

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...