Lisp/method to autoadjust Mtext height to fit inside a bounding box/rectangle?

Lisp/method to autoadjust Mtext height to fit inside a bounding box/rectangle?

Jonathan.Gray68UQW
Enthusiast Enthusiast
1,922 Views
13 Replies
Message 1 of 14

Lisp/method to autoadjust Mtext height to fit inside a bounding box/rectangle?

Jonathan.Gray68UQW
Enthusiast
Enthusiast

Does anybody know of a method/lisp/whatever that I can perform on multiple lines of Mtext where that autocad would autoadjust the height of all the lines of mtext so as I add additional lines of mtext the height of the mtext shrinks and will not vertically expend beyond my box? Expanding vertically to much is my key issue.

 

I also want/wish that I could set the starting height of the mtext too, so that if there is only one line of mtext this suggested method/lisp/whatever does not adjust this single line of mtext to fill the box.

 

Basically want mtext to shrink in height as I add additional lines of mtext so that the text doesn't expend vertically outside of a box.

 

 

 

 

 

 

0 Likes
Accepted solutions (1)
1,923 Views
13 Replies
Replies (13)
Message 2 of 14

ВeekeeCZ
Consultant
Consultant

Provide an example dwg.

0 Likes
Message 3 of 14

Jonathan.Gray68UQW
Enthusiast
Enthusiast

Will do!  Thanks for any future help.

0 Likes
Message 4 of 14

ВeekeeCZ
Consultant
Consultant

Is the MTEXT always aligned to the MC point? Is the point always in the middle of the box? Always horizontal?

Guess you want to just manual adjustment... selecting just one pair. Or multiple? Overlaps?

 

... I would simply iterate the text height by .2 until it fits.

 

0 Likes
Message 5 of 14

Jonathan.Gray68UQW
Enthusiast
Enthusiast

Hey, I need to do these hundreds of times with boxes of various sizes. Know of a lisp? 

0 Likes
Message 6 of 14

ronjonp
Mentor
Mentor

You're making this harder than it needs to be:

image.png

0 Likes
Message 7 of 14

Jonathan.Gray68UQW
Enthusiast
Enthusiast

Hey thanks for the reply, but I can't adjust the size of the existing boxes/rectangles at all. They have to stay their current size. 

0 Likes
Message 8 of 14

ВeekeeCZ
Consultant
Consultant

No, I don't. But I do know how to write one. And I could do that if that would be simple enough... but at this point, I don't have enough info to do that and you're not answering.

Anyway, the best would be if you post some minor portion of a real drawing containing these texts... because the big question is how to match a text with its frame!

0 Likes
Message 9 of 14

ronjonp
Mentor
Mentor
Accepted solution

I'm feeling generous today 8-)

(defun c:foo (/ h i ll lw mp mt o p s ur)
  ;; RJP » 2019-07-26
  (cond
    ((and (setq s (ssget ":L" '((0 . "mtext,lwpolyline")))) (> (sslength s) 1))
     (foreach x	(vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
       (setq o (vlax-ename->vla-object x))
       (vla-getboundingbox o 'll 'ur)
       (setq p (mapcar 'vlax-safearray->list (list ll ur)))
       (setq h (abs (apply '- (mapcar 'cadr p))))
       (setq mp (polar (car p) (angle (car p) (cadr p)) (/ (distance (car p) (cadr p)) 2.)))
       (if (= "MTEXT" (cdr (assoc 0 (entget x))))
	 (setq mt (cons (list o h mp) mt))
	 (setq lw (cons (list o h mp) lw))
       )
     )
     (foreach m	mt
       (cond
	 ((and (vl-some '(lambda (x) (and (equal (last m) (last x) (/ (cadr m) 2.)) (setq i x))) lw)
	       (> (cadr m) (cadr i))
	  )
	  (vla-scaleentity (car m) (vlax-3d-point (last m)) (/ (cadr i) (cadr m)))
	  (vlax-invoke (car m) 'move (last m) (last i))
	 )
       )
     )
    )
  )
  (princ)
)
(vl-load-com)

2019-07-26_9-44-29.gif

Message 10 of 14

Jonathan.Gray68UQW
Enthusiast
Enthusiast

delete this message. 

 

 

0 Likes
Message 11 of 14

Jonathan.Gray68UQW
Enthusiast
Enthusiast

This is wonderful!!!

 

I have one final question, is there any way or perhaps a new routine/lisp to make the text "smart" so that if I add additional lines of text that it will "smart enough" as to shink it's size automatically? You know when you start the mtext command you draw a box, I wish I could get mtext to never leave that defined box size, so it kepts auto shrinking to fit the originally drawn box limits. 

0 Likes
Message 12 of 14

ronjonp
Mentor
Mentor

What you are asking can be done with reactors but they are not my forte ... The code I provided should be fast enough right? It even cleans up text that is not directly centered on the rectangle.

0 Likes
Message 13 of 14

Jonathan.Gray68UQW
Enthusiast
Enthusiast

Thank you for everything! You have helped me out 😉

0 Likes
Message 14 of 14

ronjonp
Mentor
Mentor

@Jonathan.Gray68UQW wrote:

Thank you for everything! You have helped me out 😉


Glad to help (y).

0 Likes