Set Multiple/Selected Mtext Tracking/Kerning

Set Multiple/Selected Mtext Tracking/Kerning

LOESCH_PK
Advocate Advocate
2,312 Views
8 Replies
Message 1 of 9

Set Multiple/Selected Mtext Tracking/Kerning

LOESCH_PK
Advocate
Advocate

Hello everyone! How are you doing?

 

Autocad Mtexts have character formatting property called tracking (spacing of letters). This is not a object / style property, but a formating 'tag' in contents of Mtext.

I need to update several hundreds of Mtext to have different tracking (all are 1, need them to be 1.25).

I have found a LISP that allows me to make new Mtext with preset tracking value (see attached).

 

Can anybody please try to rewrite it so that I can use it as follows:

1. (best case) - first ask what is prefered tracking value - say I input 1.25

2. asks to select multiple Mtext (I select all that I want to change)

3. command adds tracking formating to all selected mtext.

 

I see it as a script that takes all contents of Mtext and adds formating "tag" ({\Tx.xx;my content incl. fields} in front.

 

There might be collision with any previous or partial formatting used in a Mtext, but I can even strip all Mtexts of previous formatting, and only then execute LISP.

 

LOESCH_PK_0-1605284607847.png

 

LOESCH_PK_1-1605284808935.png

Can anybody help me with that?

0 Likes
Accepted solutions (1)
2,313 Views
8 Replies
Replies (8)
Message 2 of 9

pbejse
Mentor
Mentor
Accepted solution

@LOESCH_PK wrote:

1. (best case) - first ask what is prefered tracking value - say I input 1.25

2. asks to select multiple Mtext (I select all that I want to change)

3. command adds tracking formating to all selected mtext.

 

I see it as a script that takes all contents of Mtext and adds formating "tag" ({\Tx.xx;my content incl. fields} in 


dsfasd

;;-------------------=={ 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
            )
        )
    )
)

(defun C:MTT125 ( / ssMtext i e)
(setq Tv (cond ((getreal
        (strcat "\nEnter Tracking value <" (rtos (setq Tv
              (cond ( Tv ) ( 1.25 ))) 2 ) ">: "
        )
      )
    )
    ( Tv )
  )
)
(if
  (setq ssMtext (ssget "_:L" '((0 . "MTEXT"))))
  (repeat (setq i (sslength ssMtext))
    (setq e (vlax-ename->vla-object (ssname ssMtext (setq i (1- i)))))
    (setq str (LM:UnFormat (vla-get-textstring e) nil))
    (Vla-put-textstring e (strcat "{\\T" (rtos Tv 2) ";" str "}"))
    )
  )
  (princ)
 )

HTH

 

 

Message 3 of 9

LOESCH_PK
Advocate
Advocate

Even better that I have asked for :-). Thank You very much!

0 Likes
Message 4 of 9

pbejse
Mentor
Mentor

@LOESCH_PK wrote:

Even better that I have asked for :-). Thank You very much!


 

Glad to hear that, and You are welcome 😎

 

 

0 Likes
Message 5 of 9

lauraq_LSA
Observer
Observer

I've gotten a lisp routine that will allow me to create new text with a designated tracking value but I can't seem to get this one that will convert existing text to work. I'm quite new to lisp routines, what is the command line to run this?

0 Likes
Message 6 of 9

Sea-Haven
Mentor
Mentor

1st answer is type MTT125 after loading.

 

2nd comment the code expects MTEXT not TEXT so you may need to use txt2mtxt to convert first. This could be built in to the pbe code.

 

Please confirm Mtext or Text.

0 Likes
Message 7 of 9

lauraq_LSA
Observer
Observer
thank you for the response. I need mine set to .95 instead of 1.25 can I
simply adjust everywhere it says 1.25 to .95?
0 Likes
Message 8 of 9

Sea-Haven
Mentor
Mentor

Yes or ask for a value (setq k (getreal "\nEnter kern size ")) replace 1.25 with k

0 Likes
Message 9 of 9

RobertFW68J2
Explorer
Explorer

Is there a way to alter this so that it does not strip the row spaces in the mtext? I have mtext with certain words that need to be on the top line, and the 2nd line, and the 3rd line, etc. They are already on the correct lines but when I run this lisp it strips the the carriage returns from the mtext. 

0 Likes