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

Mtext to Dtext & Change font to all Text Styles

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
d.decarolisK8YUC
1209 Views, 5 Replies

Mtext to Dtext & Change font to all Text Styles

Dear All,
can you please help me on this? My aim is to create a Lisp that converts all Mtext to Dtext in Model and every Layout and also that changes the font of each Text Style available into Simplex.shx.

By searching around this forum I have been able to find the following codes:

- changes all the Mtext to Dtext for all the texts in the layouts but it does not work on the texts in the model space:

 

(defun c:xplodemtext (/ myss)
(foreach layout (layoutlist)
(setvar "ctab" layout)
(setq myss (ssget "X" '((0 . "MTEXT"))))
(setvar "qaflags" 1)
(command "EXPLODE" myss "")
(setvar "qaflags" 0)
(princ)
)
(setq myss (ssget "X" '((0 . "MTEXT"))))
(setvar "qaflags" 1)
(command "EXPLODE" myss "")
(setvar "qaflags" 0)
(princ)
)
)


- Applies the selected font to every Text Style (using the command "(styles2one "simplex.shx")" )

(defun styles2one (newfont / styl)
(while (setq styl (tblnext "STYLE" (not styl)))
(setq styl (entget (tblobjname "STYLE" (cdr (assoc 2 styl)))))
(entmod (subst (cons 3 newfont) (assoc 3 styl) styl))
)
(command "_.regen")
(princ)
)

Is it possible to adjust the first script and to merge it with the second one?

Thanks in advance for the answers 🙂 

5 REPLIES 5
Message 2 of 6


@d.decarolisK8YUC wrote:

.... it does not work on the texts in the model space:

(defun c:xplodemtext (/ myss)
(foreach layout (layoutlist)
....

.... 


 

For that part, it looks like it should work if you're in Model space when you call it.  Or, try omitting the second round, and replacing that (foreach) list argument with:

  (foreach layout (cons "Model" (layoutlist))

Kent Cooper, AIA
Message 3 of 6


@d.decarolisK8YUC wrote:

....

Is it possible to adjust the first script and to merge it with the second one?
.... 



[It's not a Script, by the way -- that word has a specific, and different, meaning in AutoCAD.]

 

Try this merging, also incorporating my previous suggestion:

(defun WhateverYouCallIt (newfont / myss styl)
  (foreach layout (cons "Model" (layoutlist))
    (setvar "ctab" layout)
    (if (setq myss (ssget "_X" '((0 . "MTEXT"))))
      (progn
        (setvar "qaflags" 1)
        (command "_.EXPLODE" myss "")
        (setvar "qaflags" 0)
      ); progn
    ); if
  ); foreach
  (while (setq styl (tblnext "STYLE" (not styl)))
    (setq styl (entget (tblobjname "STYLE" (cdr (assoc 2 styl)))))
    (entmod (subst (cons 3 newfont) (assoc 3 styl) styl))
  ); while
  (command "_.regen")
  (princ)
); defun

I added the (if) test for whether it finds any Mtext in a given space, because you might run into trouble if any of them don't contain any Mtext.

 

You would still use it as a function with its name in parentheses and with the font argument text supplied:

 

(WhateverYouCallIt "simplex.shx")

 

But if you would always want to use the same font, it could be hard-coded in, eliminating that argument and making a regular command name.

Kent Cooper, AIA
Message 4 of 6
Moshe-A
in reply to: Kent1Cooper

@d.decarolisK8YUC  hi,

 

check this version

 

enjoy

moshe

 

 

(vl-load-com)

(defun c:xplodeMtext (/ ename elist ss) (setvar "cmdecho" 1) (command "._undo" "_begin") (cond ((not (findfile "simplex.shx")) (vlr-beep-reaction) (prompt "\nfont simplex.shx is not found.") ); case ( t ; make sure simplex is defined (if (null (tblsearch "style" "simplex")) (command "._style" "simplex" "simplex" 0 1 0 "_n" "_n" "_n") ) (setvar "qaflags" 1) (foreach layout (cons "Model" (layoutlist)) (setvar "ctab" layout) (setq ename (entlast)) (if (setq ss (ssget "_x" '((0 . "mtext")))) (command "._explode" "_si" ss) ) (while (setq ename (entnext ename)) (setq elist (entget ename)) (if (eq (cdr (assoc '0 elist)) "TEXT") (entmod (subst (cons '7 "simplex") (assoc '7 elist) elist)) ) ); while ); foreach (setvar "qaflags" 0) ); case ); cond (command "._undo" "_end") (setvar "cmdecho" 1) (princ) ); c:xplodeMtext
Message 5 of 6
Kent1Cooper
in reply to: Moshe-A


@Moshe-A wrote:

....

.... 
  (command "._style" "simplex" "simplex" 0 1 0 "_n" "_n" "_n") 
....
(while (setq ename (entnext ename)) ....
(entmod (subst (cons '7 "simplex") (assoc '7 elist) elist)) ....

 

@d.decarolisK8YUC , just be aware that, while maybe it will sometimes give you acceptable results, the effect of that approach may be quite different from what you asked for.

 

What it does is to make a Style name "simplex", using the Simplex.shx font, and assign that Style to all the plain Text objects resulting from Exploding Mtext objects, and only  those [i.e. only objects that are new since the Exploding ].  It will not  affect any Text objects already existing in the drawing, because:  1) it does not change the Style assigned to any of those [since they will all be older  than those resulting from Exploding Mtext, and therefore not considered]; and  2) it does not  change the font assigned to any of their Styles.

 

Also, because it doesn't change the font assigned to any other Styles, it will not uniform-ize the text parts of things like Dimensions or Block Attributes.

 

Even if it was altered to also work on pre-existing plain Text objects, there are other advantages to changing the font assigned to all Styles, as your second routine does, instead of changing the Style assigned to all Text.  You could have some Styles with fixed heights, and some without, and some with other-than-1 width factors, and some with obliquing angles, and so on.  If you change the Style of all Text, those distinctions will all disappear.  But if you change the font assigned to all all Styles, those distinctions will be preserved.

 

As another cautionary note, of which you may already be aware, changing the font can alter characteristics other than just the look of the characters.  You could have Dimensions whose text content gets kicked outside the extension lines.  Text objects will get longer or shorter, and when longer, some may overlap with other things.  MultiLeaders [which won't be Exploded in any of the routines here so far -- you could add Exploding those into the mix, before Exploding Mtext], could have their word-wrapping locations and therefore possibly also their number of lines changed.  Etc.

Kent Cooper, AIA
Message 6 of 6

Thanks to everyone for the effort. Kent1Cooper's routine works like a charm!

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

Post to forums  

Forma Design Contest


Autodesk Design & Make Report