Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Background Fill & Mtext Box

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
msarqui
662 Views, 6 Replies

Background Fill & Mtext Box

Hello guys.

I wish someone could put together these two routines that I found here in the Autodesk discussion groups.

The first one (MtextMask.lsp) creates a background mask in Mtexts.

The second one (FixMText.lsp) resizes the limits of the Mtext box to the minimum size required to cover the text with the bacground mask. 

I think it would be helpful if the two could be merged.

I am using autocad 2009 and 2012.
 
6 REPLIES 6
Message 2 of 7
pbejse
in reply to: msarqui


@msarqui wrote:
Hello guys.

I wish someone could put together these two routines that I found here in the Autodesk discussion groups.


I think it would be helpful if the two could be merged.

Easiest way to do that with minimal changes to the orignal codes:

 

Change this line <FixMText>

 

(if ss
    (princ (strcat "\nNumber of mtext objects modified: " (itoa cnt)))
  )

 to

 

(if ss
    (progn
    (princ (strcat "\nNumber of mtext objects modified: " (itoa cnt)))
    (sssetfirst nil ss))
  )

 

Then use this:

 

(defun c:CFM ()
  	(setvar 'pickfirst 1)
  	(c:FMT)
  	(c:MTM)
  )

 

Make sure both Lisp are loaded

 

command: CFM

 

Message 3 of 7
msarqui
in reply to: pbejse

Thank you very much my friend,

 

It works pretty well now.

 

I'd like to ask you something. I realized that the Mtext Boxes routine can fit very well the width of the text. But in relation to the height that does not happen. There is the possibility to fix this?

 

Thanks!

 

 

 

Message 4 of 7
pbejse
in reply to: msarqui


@msarqui wrote:

Thank you very much my friend,

 

It works pretty well now.

 

I'd like to ask you something. I realized that the Mtext Boxes routine can fit very well the width of the text. But in relation to the height that does not happen. There is the possibility to fix this?

 

Thanks!


 [again to minimize changes on the orignal code]

 

Along with the previous mod.

(defun c:MTH (/ ent ss i)
    (if (setq ss (ssget '((0 . "MTEXT"))))
	  (repeat (setq i (sslength ss))
	    	(setq ent (entget (ssname ss (setq i (1- i)))))
      (entmod
        (subst (cons 46 (cdr (assoc 40 ent))) (assoc 46 ent) ent)
        )
      )
      )
    (sssetfirst nil ss)
    )

 

 

(defun c:CFM ()
  	(setvar 'pickfirst 1)
  	(c:FMT)
        (c:MTH)
  	(c:MTM)
  )

 

Keep it mind, there are cases that  the MTEXT properties are so messed up both codes for width and height wont work at all.

 

EDIT: mispelled variable name

Message 5 of 7
pbejse
in reply to: pbejse

 for multi line Mtext <untested>

 

(defun c:MTH (/ ent ss i)
    (if (setq mpl 1 ss (ssget '((0 . "MTEXT"))))
	  (repeat (setq i (sslength ss))
	    	(setq ent (entget (ssname ss (setq i (1- i))))
		      str (cdr (assoc 1 ent)))
	    	(while (setq n (vl-string-search "\\P" str))
		  		(setq str (substr str (+ n 3)) mpl (1+ mpl))
		  )
	    
      (entmod
        (subst (cons 46 (* (* (cdr (assoc 40 ent)) mpl) 1.5)) (assoc 46 ent) ent)
        )
      )
      )
    (sssetfirst nil ss)
    )

 

Message 6 of 7
msarqui
in reply to: pbejse

It's really weird. Sometimes it works for the heigth, sometimes not. But okay, the most important was to unite the two routines and they are working. Thank you very much!

Message 7 of 7
pbejse
in reply to: msarqui


@msarqui wrote:

It's really weird. Sometimes it works for the heigth, sometimes not. But okay, the most important was to unite the two routines and they are working. Thank you very much!


You are welcome Smiley Happy

Glad it work for you msarqui, I did not notice that behavior too.I will look into it later

 

Cheers

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost