I have mtext in several drawings that contains an error that'd I'd like to fix using Lisp. An example of what this text should look like is:
NOTE:
SEE DRAWING XXXX FOR DRIVE DETAILS
The fist problem is that all of the text after the note has a width factor of 0.1 and is all squished together. The second problem is that the text height of the title (the "NOTE:" part) is supposed to be larger than the actual note (the "SEE DRAWING XXXX FOR DRIVE DETAILS" PART). Is there a way to fix this using lisp? I had a lisp in progress (not done) which is:
(IF
(SETQ SSET (SSGET "X" '((0 . "MTEXT"))))
(PROGN
(SETQ COUNT -1)
(WHILE (< (SETQ COUNT (1+ COUNT)) (SSLENGTH SS))
(SETQ ENTDATA (ENTGET (SSNAME SSET COUNT)))
(SETQ ENTTEXT (CDR (ASSOC 1 ENTDATA)))
(ENTMOD (SUBST (CONS 1 (STRCAT "{\\W1;" ENTTEXT "}")) (ASSOC 1 ENTDATA) ENTDATA))
The last line has no effect on the width factor of the note. Any ideas?
This is the entdata for this particular piece of mtext (they aren't all the same):
((-1 . <Entity name: 7ffff79ce50>) (0 . "MTEXT") (330 . <Entity name:
7ffffb069f0>) (5 . "392FD") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
"5") (100 . "AcDbMText") (10 676.276 751.03 0.0) (40 . 3.008) (41 . 0.0) (46 .
0.0) (71 . 1) (72 . 1) (1 . "{\\W1;\\pxsm0.94;{\\H2x;\\LNOTE:\\P\\W0.1;\\l
\\PSEE DRAWING XXXX FOR DRIVE DETAILS}}") (7 . "3_32") (210 0.0 0.0
1.0) (11 1.0 0.0 0.0) (42 . 24.3061) (43 . 27.1035) (50 . 0.0) (73 . 1) (44 .
0.411914))
Maynard_Rowley,
for the width factor you can try something like this:
(IF (SETQ SSET (SSGET '((0 . "MTEXT")))) (PROGN (SETQ COUNT -1) (WHILE (< (SETQ COUNT (1+ COUNT)) (SSLENGTH SSet)) (SETQ ENTDATA (ENTGET (SSNAME SSET COUNT))) (SETQ ENTTEXT (CDR (ASSOC 1 ENTDATA))) (setq newenttext (vl-string-subst "\\W1.0;" "\\W0.1;" ENTTEXT)) (ENTMOD (SUBST (CONS 1 newenttext) (ASSOC 1 ENTDATA) ENTDATA)) ) ) )
HTH
Henrique
Thank you! That worked with a slight modification (code below). Now I just need to work on changing the height. I think I should be able to work that out.
(DEFUN C:TEST ( / COUNT ENTDATA ENTTEXT NEWENTTEXT SSET)
(VL-LOAD-COM)
(IF
(SETQ SSET (SSGET "X" '((0 . "MTEXT"))))
(PROGN
(SETQ COUNT -1)
(WHILE (< (SETQ COUNT (1+ COUNT)) (SSLENGTH SSET))
(SETQ ENTDATA (ENTGET (SSNAME SSET COUNT)))
(SETQ ENTTEXT (CDR (ASSOC 1 ENTDATA)))
(SETQ NEWENTTEXT (VL-STRING-SUBST '"\\W1.0;" '"\\W0.1;" ENTTEXT))
(ENTMOD (SUBST (CONS 1 NEWENTTEXT) (ASSOC 1 ENTDATA) ENTDATA))
); END WHILE
); END PROGN
); END IF
); END DEFUN
Now I am wondering what I can do if I don't know the width factor. Is there a way to add a wildcard to that all width factors are replaced with W1.0? I was thinking something like this (which doesn't work BTW):
(SETQ NEWENTTEXT (VL-STRING-SUBST '"\\W1.0;" '"\\W*;" ENTTEXT))
@Maynard_Rowley wrote:
Now I am wondering what I can do if I don't know the width factor. Is there a way to add a wildcard to that all width factors are replaced with W1.0? I was thinking something like this (which doesn't work BTW):
(SETQ NEWENTTEXT (VL-STRING-SUBST '"\\W1.0;" '"\\W*;" ENTTEXT))
Something like this perhaps.
Your code revised, (not tested)
(DEFUN C:TEST ( / COUNT ENTDATA ENTTEXT I N PAT SSET) (VL-LOAD-COM) (IF (SETQ SSET (SSGET "X" '((0 . "MTEXT")))) (PROGN (SETQ COUNT -1) (WHILE (< (SETQ COUNT (1+ COUNT)) (SSLENGTH SSET)) (SETQ ENTDATA (ENTGET (SSNAME SSET COUNT))) (SETQ ENTTEXT (CDR (ASSOC 1 ENTDATA))) (setq i 1 n 1) (while (setq i (vl-string-search "\\W" ENTTEXT i)) (setq n (vl-string-search ";" ENTTEXT i) pat (substr ENTTEXT (+ i 3) (- n (+ i 2)))) (if (not (equal pat "1.0")) (setq ENTTEXT (strcat (substr ENTTEXT 1 (+ i 1)) "W1.0" (substr ENTTEXT (1+ n) (strlen ENTTEXT)))) );; if (setq i (1+ i)) );; while (ENTMOD (SUBST (CONS 1 ENTTEXT) (ASSOC 1 ENTDATA) ENTDATA)) ); END WHILE ); END PROGN ); END IF ); END DEFUN
HTH
Henrique
This is exactly the foundation of code I needed. Mine allows the user to define the width and select individual MTEXT entities to modify:
(defun c:mtext_width ( / adoc eFlag *error* tWF ssText cntr tList tVal i n pat) (vl-load-com) (setq adoc (vla-get-activedocument (vlax-get-acad-object))) (vla-startundomark adoc) (setvar "cmdecho" 0) (setq eFlag 1) (defun *error* (msg) (if (member msg '("Function cancelled" "console break" "quit / exit abort" "Conversion failed." "*Cancel*")) (progn (setvar "cmdecho" 1) (vla-endundomark adoc) (cond ((= eFlag 1)(princ "\n Routine aborted ")) ((= eFlag 2) (progn (princ (strcat "\n\033\n " (itoa cntr) " text objects modified.")) (princ "\n Routine complete ") ) ;progn ) ) ;cond ) ;progn ) ;if ) ;*error* (if (= (setq tWF (getreal "\n\033\n <0.8> Text width factor: ")) nil) (setq tWF 0.8)) (if (and (princ "\n\033\n <> Select text objects <> ") (setq ssText (ssget '((0 . "MTEXT")))) ) ;and (progn (setq cntr 0) (while (< cntr (sslength ssText)) (setq tList (entget (ssname ssText cntr))) (setq tVal (cdr (assoc 1 tList))) (setq i 1) (setq n 1) (while (setq i (vl-string-search "\\W" tVal i)) (setq n (vl-string-search ";" tVal i)) (setq pat (substr tVal (+ i 3) (- n (+ i 2)))) (if (not (equal pat tWF)) (setq tVal (strcat (substr tVal 1 (+ i 1)) "W" (rtos tWF) (substr tVal (1+ n) (strlen tVal)) ) ;strcat ) ;setq ) ; if (setq i (1+ i)) ) ; while (entmod (subst (cons 1 tVal) (assoc 1 tList) tList)) (setq cntr (1+ cntr)) (princ) ) ;while (setq eFlag 2) (exit) ) ;progn (progn (princ "\n\033\n Text object required ")(exit)) ) ;if ) ;mtext_width
Thanks guys!