Results 1 to 5 of 5

Thread: Change color of existing MTEXT Objects

  1. #1
    Member chad.beussink's Avatar
    Join Date
    2006-08
    Posts
    23
    Login to Give a bone
    0

    Question Change color of existing MTEXT Objects

    I am trying to get a lisp routine to change the color of MTEXT using a list routine.

    Say I have some MTEXT with the color set to green within the TEXT EDITOR. Just by simply changing the PROPERTIES to white, the color still appears green. The only way to change the color is to open up each individual text in TEXT EDITOR and change the color that way. This is time consuming because it must be done 1 at a time. Does anyone have a lisp routine that would make this easier?

    Thanks,
    Chad Beussink
    TPS Engr
    TGMO, Perryville MO

  2. #2
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Change color of existing MTEXT Objects

    Strips out formation for color, font, height and width.
    Change this line
    Code:
    (member (strcase cstr2) '("C" "F" "H" "W"))
    if you only want color erase the the others, so it would look like
    Code:
    (member (strcase cstr2) '("C"))
    Code:
    (defun c:StpMtext (/ ss ent1 ent2 tstr1 tstr2)
    ; Strips Mtext of certain formating
    
    (command "_.undo" "_end")
    (command "_.undo" "_group")
    (if (setq ss (ssget '((0 . "MTEXT"))))
     (while (/= (sslength ss) 0)
      (setq ent1 (ssname ss 0))
      (setq ent2 (vlax-ename->vla-object ent1))
      (setq tstr1 (vlax-get ent2 'TextString))
      (setq tstr2 (StripString tstr1))
      (vlax-put ent2 'TextString tstr2)
      (ssdel ent1 ss)
     ); while
    ); if
    (command "_.undo" "_end")
    (princ)
    )
    
    ;-------------------------------------
    
    (defun StripString (String / cstr1 cstr2 nString cnt1 tstr1)
    ; Strips out formation for color, font, height and width.
    
    (setq cnt1 1)
    (while (and (setq cstr1 (substr String 1 1)) (> (strlen String) 0))
     (if (= cstr1 "\\")
      (progn
       (setq cstr2 (substr String 2 1))
       (if (member (strcase cstr2) '("C" "F" "H" "W"))
        (progn
         (while (/= (substr String cnt1 1) ";")
          (setq cnt1 (1+ cnt1))
         ); while
         (setq String (substr String (1+ cnt1) (strlen String)))
         (setq cnt1 1)
        ); progn
        (progn
         (if nString
          (setq nString (strcat nString (substr String 1 1)))
          (setq nString (substr String 1 1))
         ); if
         (setq String (substr String 2 (strlen String)))
        ); progn
       ); if
      ); progn
      (progn
       (if nString
        (setq nString (strcat nString (substr String 1 1)))
        (setq nString (substr String 1 1))
       ); if
       (setq String (substr String 2 (strlen String)))
      ); progn
     ); if
    ); while
    (setq tstr1 (vl-string->list nString))
    (if (and (not (member 92 tstr1)) (member 123 tstr1))
     (setq tstr1 (vl-remove-if '(lambda (x) (or (= x 123) (= x 125))) tstr1))
    ); if
    (vl-list->string tstr1)
    )

  3. #3
    100 Club
    Join Date
    2009-01
    Location
    Warsaw Poland
    Posts
    130
    Login to Give a bone
    0

    Default Re: Change color of existing MTEXT Objects

    Quote Originally Posted by T.Willey View Post
    Strips out formation for color, font, height and width.
    Change this line
    Code:
    (member (strcase cstr2) '("C" "F" "H" "W"))
    if you only want color erase the the others, so it would look like
    Code:
    (member (strcase cstr2) '("C"))
    Great work Willey

    i have similar problem - i have different width in some Mtexts and i want them all to be the same - the best would be if the width was just as it is set in text style

    or mayby there is possibility to make all selected Mtext to have width=0.8 using this LISP by Willey??

  4. #4
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Change color of existing MTEXT Objects

    I would strip out the formatting code for width, then assign a value to the dxf code for width, that way you can change it easily next time. I'm not sure which code it is off hand, but I would look in the 40's somewhere.

  5. #5
    100 Club
    Join Date
    2009-01
    Location
    Warsaw Poland
    Posts
    130
    Login to Give a bone
    0

    Default Re: Change color of existing MTEXT Objects

    Quote Originally Posted by T.Willey View Post
    I would strip out the formatting code for width, then assign a value to the dxf code for width, that way you can change it easily next time. I'm not sure which code it is off hand, but I would look in the 40's somewhere.
    i dont really understand you Willey because i'm not LISP programmer, but it seems like my problem is no longer a problem

    anyway thanx for help! :--)

Similar Threads

  1. Change the color of XRef'd objects
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 1
    Last Post: 2017-01-10, 04:52 AM
  2. Replies: 3
    Last Post: 2014-07-11, 06:53 PM
  3. Replies: 7
    Last Post: 2010-11-11, 08:20 PM
  4. Command to Change Color of Mtext to BYLAYER
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 8
    Last Post: 2010-01-22, 10:58 PM
  5. Replies: 8
    Last Post: 2007-03-12, 02:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •