Anuncios

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

UNDERLINE MULTIPLE MTEXT ENTITIES

cleftwich
Enthusiast

UNDERLINE MULTIPLE MTEXT ENTITIES

cleftwich
Enthusiast
Enthusiast

Does anyone know how to underline multiple mtext entities at one time through a lisp or other means. Currently I use an archaic and time consuming way of completing this task, any help would be appreciated greatly,

 

Thanks,

Charles

0 Me gusta
Responder
Soluciones aceptadas (2)
7.793 Vistas
23 Respuestas
Respuestas (23)

pendean
Community Legend
Community Legend
Solución aceptada
LISP customization forum is over here (as long as you are not running the LT version of AutoCAD) https://forums.autodesk.com/t5/autocad-customization/ct-p/AutoCADTopic1

0 Me gusta

Kent1Cooper
Consultant
Consultant
Solución aceptada

I assume you mean underlining the entire content.  Try this quickie:

(defun C:UMT (/ ss n edata); = Underline MText(s)
  (if (setq ss (ssget "_:L" '((0 . "MTEXT"))))
    (repeat (setq n (sslength ss)); then
      (setq edata (entget (ssname ss (setq n (1- n)))))
      (entmod
        (subst
          (cons 1 (strcat "{\\L" (cdr (assoc 1 edata))))
          (assoc 1 edata)
          edata
        ); subst
      ); entmod
    ); repeat
  ); if
  (princ)
); defun

It's possible that if a given Mtext object has other internal formatting at the beginning, something could be thrown off.  It could be made to check whether there's already underlining code at the beginning before applying it, but in a quick test, having two of them doesn't seem to bother it.  Nor does not  having the  }  at the end that manual underlining supplies, but that can be added:

  (cons 1 (strcat "{\\L" (cdr (assoc 1 edata)) "}"))

Kent Cooper, AIA

cleftwich
Enthusiast
Enthusiast

Exactly what I was looking for thanks so much.

0 Me gusta

CAD7875
Participant
Participant

life saver!!!! thanks:cara_que_ríe_con_la_boca_abierta_y_los_ojos_sonrientes:

0 Me gusta

cleftwich
Enthusiast
Enthusiast

Thank you works perfectly

0 Me gusta

carl.lowrey
Explorer
Explorer

Thanks Kent. Great to find these little gems in the archives when you need them quickly.

0 Me gusta

chillme1
Advocate
Advocate

Placing the lisp file within my SFSP, I then tried loading UMT (load "UMT") and also (load "UMT.lsp") with no success:

 

Examples:
Command: (load "UMT")
; error: LOAD failed: "UMT"
Command: (load "UMT.lsp")
; error: LOAD failed: "UMT.lsp"

 

It is probably something basic but not sure exactly what at this point.

 

<red-faced from embarrassment but willing to ask and learn>

Thanks for your comments,

Clint Hill
0 Me gusta

chillme1
Advocate
Advocate

No sooner than I post do I (think) I see the anomaly.

Thanks for your comments,

Clint Hill
0 Me gusta

chillme1
Advocate
Advocate

The error from my copy/paste attempt is: error: extra right paren on input

Thanks for your comments,

Clint Hill
0 Me gusta

Kent1Cooper
Consultant
Consultant

It works for me.  In case something went wacky in your copy/pasting, try the attached.  [And use the file name -- (load "UnderlineMText") -- not just the command name; change the file name if you prefer.]

Kent Cooper, AIA

chillme1
Advocate
Advocate

Kent, You have my sincere thanks in taking time to contribute. I look forward to using your code as a learning tool as well.

Thanks for your comments,

Clint Hill
0 Me gusta

leandro_miya
Explorer
Explorer

Hi guys,

 

Is it possible to change the code for simple Text? If so, what changes should I make?

 

Sorry to bother, but I don't know lisp yet.

 

Thanks!

Kent1Cooper
Consultant
Consultant

@leandro_miya wrote:

.... Is it possible to change the code for simple Text? If so, what changes should I make? ....


Try this modification -- the red parts are all that I changed [untested]:

(defun C:UT (/ ss n edata); = Underline Text(s)
  (if (setq ss (ssget "_:L" '((0 . "TEXT"))))
    (repeat (setq n (sslength ss)); then
      (setq edata (entget (ssname ss (setq n (1- n)))))
      (entmod
        (subst
          (cons 1 (strcat "%%U" (cdr (assoc 1 edata))))
          (assoc 1 edata)
          edata
        ); subst
      ); entmod
    ); repeat
  ); if
  (princ)
); defun

If any selected Text object has its entire contents already underlined by the same %%U entry at the beginning, the above will un-underline it.  It could be made to check for that, if desired, and not add another %%U.

Kent Cooper, AIA
0 Me gusta

sam_underdown
Observer
Observer

@Kent1Cooper Is it possible to create a similar lisp routine where it removes the underline, rather than applying it? I'm still learning about lisp routines, apologies if you have answered this query elsewhere 

0 Me gusta

Kent1Cooper
Consultant
Consultant

@sam_underdown wrote:

.... Is it possible to create a similar lisp routine where it removes the underline, rather than applying it? .... 


Quickly, with minimal testing:

(defun C:UUT (/ ss n edata); = Un-Underline Text(s)
  ;; to remove all underlining from Text objects
  (if (setq ss (ssget "_:L" '((0 . "TEXT"))))
    (repeat (setq n (sslength ss)); then
      (setq
        edata (entget (ssname ss (setq n (1- n))))
        txt (cdr (assoc 1 edata))
      ); setq
      (while (wcmatch txt "*%%U*")
        (setq txt (vl-string-subst "" "%%U" txt))
      ); while
      (entmod (subst (cons 1 txt) (assoc 1 edata) edata))
    ); repeat
  ); if
  (princ)
); defun

(defun C:UUMT (/ ss n edata); = Un-Underline MText(s)
  ;; to remove underlining from Mtext whose ENTIRE content is underlined
  (if (setq ss (ssget "_:L" '((0 . "MTEXT") (1 . "{\\L*"))))
    (repeat (setq n (sslength ss)); then
      (setq
        edata (entget (ssname ss (setq n (1- n))))
        txt (cdr (assoc 1 edata))
      ); setq
      (entmod
        (subst
          (cons 1 (substr txt 4 (- (strlen txt) 4)))
          (assoc 1 edata)
          edata
        ); subst
      ); entmod
    ); repeat
  ); if
  (princ)
); defun

But NOTE the description for UUMT, that it's for Mtext whose entire content is underlined [just as the earlier routines were built to apply underlining only to entire content].  It depends on its content starting with "{\\L"  and ending with "}".  If it starts with underlined content but the underlining doesn't go under all of it, it will lose the last "real" character in place of losing the "}", because it just takes off the last character, whatever that is.

 

Part of "minimal testing" is that I looked at combinations of underline and color formatting, and found that if both are applied from the beginning of the content, the underlining format code always seems to come before the color code, no matter in which order they were applied, so it seems to appropriately take off the underlining code but leave the color code.  But if the underlining doesn't go all the way, odd stuff is left in the text string at the point where it ended, though the visible object looks right.  I did not try other kinds of formatting [e.g. tracking, width factor, obliquing] for their formatting-code relationships to underlining.

 

In the case of plain Text, UUT doesn't care whether the entire content is underlined -- it removes all underline-code content, starting and stopping, wherever and however many there are.

Kent Cooper, AIA

sam_underdown
Observer
Observer

@Kent1Cooper thank you for your quick response. I have created the lisp routine using the coding provided; the command loads as normal but when i highlight/click the group of mtext that needs to be amended, it states nothing has been selected, any idea why? i have attached the lisp routine file below if you want to check it 

 

Thanks for your assistance 

0 Me gusta

Kent1Cooper
Consultant
Consultant

@sam_underdown wrote:

... when i highlight/click the group of mtext that needs to be amended, it states nothing has been selected.... 


Locked Layer(s)?  Mtext that doesn't have the underlining code right at the start, including something else like obliquing from the start if its code element gets in ahead of the underlining code?  You used the UUT command name but picked Mtext objects?  [I wouldn't name the file the way you did, since it also includes one for plain Text.]

Kent Cooper, AIA
0 Me gusta

sam_underdown
Observer
Observer

All layers are unlocked, the level is displayed as +100.00

 

I have removed the + sign and the command works, the + sign was causing me the problem! 

 

Thank you 

0 Me gusta

Kent1Cooper
Consultant
Consultant

@sam_underdown wrote:

.... the level is displayed as +100.00

I have removed the + sign and the command works, the + sign was causing me the problem! 

....


There must be something else going on.  When I make Mtext just like that, UUMT works to remove the underlining.  Do this at the Command line:

(cdr (assoc 1 (entget (car (entsel)))))

and select an Mtext object that UUMT doesn't work on [i.e. that is not recognized in UUMT's selection].  What does it return?  The one I made returns this:

"{\\L+100.0}"

and I suspect yours will have some other complication making it not fit the selection filter criteria.  [Like maybe, does the underlining actually start after the + sign?]

Kent Cooper, AIA
0 Me gusta