strip mtext formatting

strip mtext formatting

mruPRQUJ
Advocate Advocate
8,679 Views
58 Replies
Message 1 of 59

strip mtext formatting

mruPRQUJ
Advocate
Advocate

Hi,

 

Is it possible to create a lisp to strip mtext formatting? like, width factor, tracking and oblique angle. The attached lisp can strip mtext, but not formatting. Thank you very much in advance, 🙂

0 Likes
Accepted solutions (2)
8,680 Views
58 Replies
Replies (58)
Message 21 of 59

ronjonp
Advisor
Advisor

@mruPRQUJ Have you tried THIS ?

Quick test and it removed width factor:

(LM:UnFormat "adasd{\\W2.1;sa\\W1;\\Odads}" t)
;; Returns "adasdsadads" 
Message 22 of 59

mruPRQUJ
Advocate
Advocate

Hi,

 

I tried it, it can only strip mtext width, not width factor, thanks.

0 Likes
Message 23 of 59

ronjonp
Advisor
Advisor
Accepted solution

@mruPRQUJ wrote:

Hi,

 

I tried it, it can only strip mtext width, not width factor, thanks.


Not according to my test..

 

Try it: 

 

(defun c:foo (/ e)
;;-------------------=={ UnFormat String }==------------------;;
;;                                                            ;;
;;  Returns a string with all MText formatting codes removed. ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  str - String to Process                                   ;;
;;  mtx - MText Flag (T if string is for use in MText)        ;;
;;------------------------------------------------------------;;
;;  Returns:  String with formatting codes removed            ;;
;;------------------------------------------------------------;;

(defun LM:UnFormat ( str mtx / _replace rx )

    (defun _replace ( new old str )
        (vlax-put-property rx 'pattern old)
        (vlax-invoke rx 'replace str new)
    )
    (if (setq rx (vlax-get-or-create-object "VBScript.RegExp"))
        (progn
            (setq str
                (vl-catch-all-apply
                    (function
                        (lambda ( )
                            (vlax-put-property rx 'global     actrue)
                            (vlax-put-property rx 'multiline  actrue)
                            (vlax-put-property rx 'ignorecase acfalse) 
                            (foreach pair
                               '(
                                    ("\032"    . "\\\\\\\\")
                                    (" "       . "\\\\P|\\n|\\t")
                                    ("$1"      . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]")
                                    ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);")
                                    ("$1$2"    . "\\\\(\\\\S)|[\\\\](})|}")
                                    ("$1"      . "[\\\\]({)|{")
                                )
                                (setq str (_replace (car pair) (cdr pair) str))
                            )
                            (if mtx
                                (_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str))
                                (_replace "\\"   "\032" str)
                            )
                        )
                    )
                )
            )
            (vlax-release-object rx)
            (if (null (vl-catch-all-error-p str))
                str
            )
        )
    )
)
(vl-load-com)
  (cond	((and (setq e (car (entsel "\\nPick mtext: ")))
	      (vlax-property-available-p (setq e (vlax-ename->vla-object e)) 'textstring)
	 )
	 (vla-put-textstring e (lm:unformat (vla-get-textstring e) t))
	)
  )
  (princ)
)

 

 

 

Message 24 of 59

mruPRQUJ
Advocate
Advocate

Hi,

 

It looks like it did not work. I may make a mistake. Please see the info below, thanks a lot!

mruPRQUJ_0-1689814574931.png

 

0 Likes
Message 25 of 59

ronjonp
Advisor
Advisor

@mruPRQUJ 

 

You have to load the code from the link I sent previously ?? 

 

Looks at the code above again I added the function. I thought I was dealing with someone more experienced with programming.

0 Likes
Message 26 of 59

mruPRQUJ
Advocate
Advocate

you mean two lisp?

0 Likes
Message 27 of 59

mruPRQUJ
Advocate
Advocate

Hi,

 

could you please provide detail how to use it? thanks a million. 

0 Likes
Message 28 of 59

ronjonp
Advisor
Advisor

@mruPRQUJ wrote:

Hi,

 

could you please provide detail how to use it? thanks a million. 


https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/strip-mtext-formatting/m-p/12113644#...

0 Likes
Message 29 of 59

mruPRQUJ
Advocate
Advocate

Hi, it is a little late. I will try it tomorrow, many thanks.

0 Likes
Message 30 of 59

ronjonp
Advisor
Advisor

Same here. Glad to be of your assistance. 😉

0 Likes
Message 31 of 59

john.uhden
Mentor
Mentor
Accepted solution

@mruPRQUJ ,

OK.  Here ya go...

John F. Uhden

Message 32 of 59

ronjonp
Advisor
Advisor

@mruPRQUJ wrote:

Hi, it is a little late. I will try it tomorrow, many thanks.


Please tell me you got it to work...

0 Likes
Message 33 of 59

mruPRQUJ
Advocate
Advocate

Hi,

 

It works prefect! If it can modify the block attribute, that would be better! Thanks a lot! 🙂

0 Likes
Message 34 of 59

mruPRQUJ
Advocate
Advocate

Hi,

 

It works, I am sorry I made a mistake. It would be better if it can modify multiple objects at one time and modify block attributes as well, thanks a lot! 🙂 

0 Likes
Message 35 of 59

B_Rainey_3366
Explorer
Explorer

@john.uhden 

 

How are ya?

I found that my 2024 AutoCAD, in the MText editor, it has a "Remove Character, Paragraph or ALL Formatting" in the right-click dialog and works on selected text. But I'm sure you know this... Right?

 

Brian

 

 

0 Likes
Message 36 of 59

john.uhden
Mentor
Mentor

Doing fine, @B_Rainey_3366 ,

Welcome to my world.

No, I didn't know that.  We're still running Civil 3D 2020.

As to the unformatting, I wonder if they used Joe Burke's/Steve Doman's code or mine.

But I don't care.  Sounds good to me.

Of course, now someone will point out to me that it was there in 2020.  But that's the way I am.  I find out that the neighbor was pregnant when the kid has turned 2.

John F. Uhden

0 Likes
Message 37 of 59

EnM4st3r
Advocate
Advocate

i just checked in 2019 and its there. But i dont know how you would access that with lisp. Is that even possible?

EnM4st3r_0-1701260156585.png

 

0 Likes
Message 38 of 59

john.uhden
Mentor
Mentor

@EnM4st3r ,

It works in 2020 as well, though I have no idea how to invoke it via AutoLisp.

John F. Uhden

0 Likes
Message 39 of 59

pendean
Community Legend
Community Legend

@EnM4st3r wrote:

i just checked in 2019 and its there. But i dont know how you would access that with lisp. Is that even possible?

EnM4st3r_0-1701260156585.png

 


Those selections are inside-editor options, LISP usage while in the editor is not possible.

0 Likes
Message 40 of 59

michellem
Advocate
Advocate

Hello Everyone;

 

Does anyone know if StripMtext has been updated recently? I tried using it on some Mtext in a cad file exported from Revit and it had problems clearing out tabs.

 

I added this section to the code and it seems to work (mostly) but my understanding Mtext format codes is lacking:

      ;Autocad seems to have revised the way it does tabs.
      ;I kept the old version and added this as a second pass.
      (setq str (RE:Replace "" "\\\\pxt[0-9.,]+;" str))
      (setq str (RE:Replace "" "\\\\pxqc,t[0-9.,]+;" str)) ;center tabs?
      (setq str (RE:Replace "" "\\\\pxqr,t[0-9.,]+;" str)) ;right tabs?
      str ;Return str

 

Sincerely;

Michelle

 

PS: I am looking for updated documentation of MText formatting codes for a project I am working on and would appreciate if someone can point me in the right direction.

0 Likes