jkoll66 Posted January 4, 2012 Share Posted January 4, 2012 I ran a batch program that searched and replaced some text on a titleblock for our current client. The program successfully found and replaced the text, but we have one bit of text that is Mtext and it is now on two lines. I need to have it on one line. I could manually select and change it, but we have 200 files that need the same change. Does anyone have a Lisp routine to stretch Mtext so all is on one line? Thanks. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 4, 2012 Share Posted January 4, 2012 The following code will set the MText width to zero, forcing the text on one line: (defun c:OneLineMText ( / i s ) (if (setq s (ssget "_X" '((0 . "MTEXT")))) (repeat (setq i (sslength s)) (vla-put-width (vlax-ename->vla-object (ssname s (setq i (1- i)))) 0.0) ) ) (princ) ) (vl-load-com) (princ) It is currently set to alter ALL MText in a drawing - to alter specific MText objects you will need to add extra filters to the ssget filter list. You didn't specify any unique characteristics of your MText, so I couldn't filter for anything. Quote Link to comment Share on other sites More sharing options...
jkoll66 Posted January 5, 2012 Author Share Posted January 5, 2012 Thanks for the reply. The line reads "WEST JEFFERSON, OH". That's all I want changed. Is there any way to isolate that text? Thanks. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 5, 2012 Share Posted January 5, 2012 On the assumption that your MText contains no formatting applied from within the editor, : (defun c:OneLineMText ( / i s ) (if (setq s (ssget "_X" '((0 . "MTEXT") (1 . "WEST JEFFERSON, OH")))) (repeat (setq i (sslength s)) (vla-put-width (vlax-ename->vla-object (ssname s (setq i (1- i)))) 0.0) ) ) (princ) ) (vl-load-com) (princ) Quote Link to comment Share on other sites More sharing options...
jkoll66 Posted January 5, 2012 Author Share Posted January 5, 2012 I tried the first routine and it worked great. However, the second does not seem to do anything. I'm afraid to run the 1st on all of the files in case there is more than one instance of Mtext. Is there any more info you need from me to get the second one working? Thanks. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 5, 2012 Share Posted January 5, 2012 Not doing anything means that no MText matching the filter has been found; does the MText have formatting applied through the MText editor? Does the string in the filter exactly match the MText content? Or, you can filter for the MText using a different property, such as its Layer, for example. Quote Link to comment Share on other sites More sharing options...
jkoll66 Posted January 5, 2012 Author Share Posted January 5, 2012 I've attached a screen print that shows you what I have. Thanks. Screen Print.docx Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 5, 2012 Share Posted January 5, 2012 Thanks. As you can see from the formatting codes in the Contents property, formatting has been applied to the MText throught the MText editor. From here you have two options: 1. Change the filter to: (defun c:OneLineMText ( / i s ) (if (setq s (ssget "_X" '((0 . "MTEXT") (1 . "*WEST JEFFERSON, OH*")))) (repeat (setq i (sslength s)) (vla-put-width (vlax-ename->vla-object (ssname s (setq i (1- i)))) 0.0) ) ) (princ) ) (vl-load-com) (princ) This will change all MText containing the words "WEST JEFFERSON, OH" 2. Include the formatting codes in the filter: (defun c:OneLineMText ( / i s ) (if (setq s (ssget "_X" '((0 . "MTEXT") (1 . "\\fArial|b0|i0|c0|p34|;WEST JEFFERSON, OH")))) (repeat (setq i (sslength s)) (vla-put-width (vlax-ename->vla-object (ssname s (setq i (1- i)))) 0.0) ) ) (princ) ) (vl-load-com) (princ) This assumes the same formatting has been applied to the other instances of this text. Quote Link to comment Share on other sites More sharing options...
jkoll66 Posted January 6, 2012 Author Share Posted January 6, 2012 Thanks, that worked great! Appreciate the help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.