Lisp to Select MText Objects and Turn on Background Mask and Frame Text

Lisp to Select MText Objects and Turn on Background Mask and Frame Text

Anonymous
Not applicable
6,160 Views
15 Replies
Message 1 of 16

Lisp to Select MText Objects and Turn on Background Mask and Frame Text

Anonymous
Not applicable

Pretty new to LISP so I'm not sure how to write this out, but I'm looking to have something that will select any multi line text object, turn on the background mask (with color set to background color), and then turn on frame text. If possible it would be extra helpful it it would also bring those objects to front.

 

Any help with this would be extremely appreciated.

0 Likes
Accepted solutions (1)
6,161 Views
15 Replies
Replies (15)
Message 2 of 16

Moshe-A
Mentor
Mentor

@Anonymous  hi,

 

>> check this <<

 

moshe

 

0 Likes
Message 3 of 16

Anonymous
Not applicable

It appears that will give me a background mask, but I'm not proficient enough to write a routine that will find all the mtext objects, turn on the background mask and turn on frame text.

 

The image shows what I'm trying to accomplish with this routine.2019-07-28_16-19-39.jpg

 

0 Likes
Message 4 of 16

dbhunia
Advisor
Advisor

Check <<THIS>> Link

 

Replace the line "(setq ss1 (ssget '((0 . "mtext")))"

 

With "(setq ss1 (ssget "_A" '((0 . "mtext")))"

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 5 of 16

Anonymous
Not applicable

That works great for the background mask! Is there anyway to frame the text within the same routine?

0 Likes
Message 6 of 16

TomBeauford
Advisor
Advisor

Not documented, but it appears that a bit code of 16 added to Mtext DXF Group 90 added the frame to Mtext I just tested.  The Frame is a simple toggle in properties though.

 

64bit AutoCAD Map & Civil 3D 2023
Architecture Engineering & Construction Collection
2023
Windows 10 Dell i7-12850HX 2.1 Ghz 12GB NVIDIA RTX A3000 12GB Graphics Adapter
0 Likes
Message 7 of 16

TomBeauford
Advisor
Advisor
Accepted solution

This code will toggle on both Background Mask and Frame Text

 

(defun c:BGtoggle (/ ss1 num cnt get_dst BGoffSet obj ent data elist mtwidth)
(setq ss1 (ssget '((0 . "mtext,text")))
num (sslength ss1)
cnt 0
)
(repeat num

(if (eq (cdr (assoc 0 (entget (setq ent (ssname ss1 cnt))))) "TEXT")
(progn (command "_.txt2mtxt" ent "")
(entmod (subst '(41 . 0.) (assoc 41 (setq data (entget (setq ent (entlast))))) data))
)
)
(setq obj (vlax-ename->vla-object ent))
(if (= (vlax-get-property obj 'BackgroundFill) :vlax-true)
(vlax-put-property obj 'BackgroundFill :vlax-false)
(progn
(vlax-put-property obj 'BackgroundFill :vlax-true)
(if (= get_dst BGoffSet nil)
(progn
(or ·×BGoff×· (setq ·×BGoff×· 1.15))
(setq get_dst (getreal (strcat"\nEnter Distance :<" (rtos ·×BGoff×·) "> ")))
(if get_dst (setq ·×BGoff×· get_dst))
(setq BGoffSet "T")
)
)
(setq ent (vlax-vla-object->ename obj)
elist (entget ent)
elist (subst (cons 90 19)(assoc 90 elist) elist) ;Use drawing background color
elist (subst (cons 45 ·×BGoff×·) (assoc 45 elist) elist) ;Set 'Border Offset Factor'
mtwidth (* (cdr (assoc 42 elist))1.015)
elist (subst (cons 41 mtwidth)(assoc 41 elist) elist) ;Trim excess width
)
(entmod elist)
) ; progn
)
(setq cnt (1+ cnt))
) ; repeat
(vl-cmdf "_draworder" ss1 "" "f")
(princ)
)

64bit AutoCAD Map & Civil 3D 2023
Architecture Engineering & Construction Collection
2023
Windows 10 Dell i7-12850HX 2.1 Ghz 12GB NVIDIA RTX A3000 12GB Graphics Adapter
0 Likes
Message 8 of 16

Anonymous
Not applicable

How can I get this to run automatically?  I can get it to run but I have to manually select "all" and enter. Everything I seem to try I can't get it

0 Likes
Message 9 of 16

dbhunia
Advisor
Advisor

use 

 

(setq ss1 (ssget "_A" '((0 . "mtext,text")))

instead of

(setq ss1 (ssget '((0 . "mtext,text")))

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 10 of 16

Anonymous
Not applicable

dbhunia that worked on selecting all Thank you very much.

 

Is there away to start this lisp automatically when opening a drawing?  I have put into startup suite and it says it doesn't recognize the command. I have others in it that it does recognize.  I can type it on the command line and it works, so it's loading it.

0 Likes
Message 11 of 16

dbhunia
Advisor
Advisor

Find acad<version>doc.lsp file in your system.........

 

and put the 2 line at the end......

(load "LISP File path")

(your function)

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 12 of 16

Anonymous
Not applicable

dbhunia with your help I'm getting close to accomplishing what I need done. Greatly appreciate it.

 

With the txt2mtxt command it turns all single line text to mtext. When it does that it shows the text format prefixes (ex: if the text has %%u to underline it it shows the %%u).  Is there away to prevent this?  Or is there a reason I'm not seeing that we would want to convert the single line text to Mtext?

 

Once again, thank you for the help you have given.

0 Likes
Message 13 of 16

TomBeauford
Advisor
Advisor

reply to csorensen

As text doesn't have either Background Mask or Text frame in Properties I added the txt2mtxt command to work with them as well.  

 

To underline Text or Mtext simply highlight and use Ctrl+U like you would in most software.  txt2mtxt works fine with that, I remember having to add %%U's when I started using AutoCAD over a quarter century ago, but haven't seen any in a drawing in a long time.  I'm sure you could still find a lisp online for converting your text easy enough if you want or just remove the conversion from the lisp.

64bit AutoCAD Map & Civil 3D 2023
Architecture Engineering & Construction Collection
2023
Windows 10 Dell i7-12850HX 2.1 Ghz 12GB NVIDIA RTX A3000 12GB Graphics Adapter
0 Likes
Message 14 of 16

Anonymous
Not applicable

how would you edit this lisp to not include the text frame on it? i love how it converts Text to Mtext then adds background that is perfect but i dont need a frame around it

Message 15 of 16

TomBeauford
Advisor
Advisor

Try http://forums.augi.com/showthread.php?77962-How-to-set-border-offset-factor-for-background-masking-M...

or http://forums.augi.com/showthread.php?131078-Is-there-a-tool-to-compact-Mtext-boxes&p=1133034&viewfu...

 

64bit AutoCAD Map & Civil 3D 2023
Architecture Engineering & Construction Collection
2023
Windows 10 Dell i7-12850HX 2.1 Ghz 12GB NVIDIA RTX A3000 12GB Graphics Adapter
Message 16 of 16

Anonymous
Not applicable

That is perfect! thank you so much!!