daisenson Posted May 22, 2012 Posted May 22, 2012 Hi everyone, Mtext has an attribute which is define width (paper and model). It seems to be read only and I can only modify it by clicking on the text grips and manualy stretching. Would there be a lisp routine that grabs all Mtexts in a drawing and multiply the defined width factor by 100? Thanks Quote
Tharwat Posted May 22, 2012 Posted May 22, 2012 Would this be of any assistance ? (defun c:Test (/ ss i sn) (vl-load-com) (if (setq ss (ssget "_:L" '((0 . "MTEXT")))) (repeat (setq i (sslength ss)) (vla-put-width (vlax-ename->vla-object (ssname ss (setq i (1- i)))) 0. )) (princ) ) (princ) ) Quote
daisenson Posted May 23, 2012 Author Posted May 23, 2012 HI Tharwat, unfortunately is not working. After scaling an Mtext I applied the script, selected the text but the paper and space defined width remain the same. Any other ideas? Thnx Quote
daisenson Posted May 23, 2012 Author Posted May 23, 2012 MSasu, That was great, the code takes bounding box to text width, but manipulating a few values managed to scale the value of the bounding box by the factor I need to scale the text, so when I scale it it will not be affected by bounding box. Thanks Quote
Gentile Romano Posted February 27, 2023 Posted February 27, 2023 (edited) On 5/22/2012 at 10:12 PM, Tharwat said: Would this be of any assistance ? (defun c:Test (/ ss i sn) (vl-load-com) (if (setq ss (ssget "_:L" '((0 . "MTEXT")))) (repeat (setq i (sslength ss)) (vla-put-width (vlax-ename->vla-object (ssname ss (setq i (1- i)))) 0.0 ) (vla-put-height (vlax-ename->vla-object (ssname ss (setq i (1- i)))) 0.0 )) (princ) ) (princ)) Help to fix this ! I have added vla-put-height as well Edited February 27, 2023 by Gentile Romano Quote
Tharwat Posted February 27, 2023 Posted February 27, 2023 How come you are changing the height of text to zero ! (vla-put-width (setq vla (vlax-ename->vla-object (ssname ss (setq i (1- i))))) 0.0) (vla-put-height vla 0.2) ;; change the height 0.2 to the one you prefer. Quote
Gentile Romano Posted February 27, 2023 Posted February 27, 2023 31 minutes ago, Tharwat said: How come you are changing the height of text to zero ! (vla-put-width (setq vla (vlax-ename->vla-object (ssname ss (setq i (1- i))))) 0.0) (vla-put-height vla 0.2) ;; change the height 0.2 to the one you prefer. Ooh vla-put-height for text height ?? I was trying to change this see below Image both to 0.0 Quote
tombu Posted February 27, 2023 Posted February 27, 2023 On 5/22/2012 at 9:02 PM, daisenson said: HI Tharwat, unfortunately is not working. After scaling an Mtext I applied the script, selected the text but the paper and space defined width remain the same. Any other ideas? Thnx In your first post you wanted to modify the Width of all Mtext in both Paper Space and Model Space, then you say you're trying to scale them. The better you describe what you need the more you'll like the responses. Are you trying to convert a drawing from meters to millimeters? Quote
Steven P Posted February 27, 2023 Posted February 27, 2023 (edited) This is what I use for individual texts: A bit slow if you have a lot of texts to modify, it loops through them finding the current width and height, rounding up to the next 2.5 (we use multiples of 2.5 for sizes so this is good for us) and then an option to adjust each texts dimensions. See if this works as you want, and can adjust it to make it quicker for lots of texts Command txtHWsnap (defun c:txtWHsnap ( / MWidth MHeight txtset LenSet Ecount Ename entlist newwidth newheight snap elist ) ;;Sub Functions (defun *error* ( msg ) (if doc (_EndUndo doc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (defun LM:roundup ( n m ) ((lambda ( r ) (cond ((equal 0.0 r 1e-8) n) ((< n 0) (- n r)) ((+ n (- m r))))) (rem n m)) ) ;;End Sub Functions (command "undo" "be") ; begin undo (setq MWidth 2.5) (setq MHeight 2.5) (setq txtset (ssget '((0 . "MTEXT")))) (setq LenSet (sslength txtSet)) (setq Ecount 0) (repeat LenSet (setq Ename (ssname txtset Ecount)) (setq entlist (entget Ename)) (setq newwidth (cdr (assoc 41 entlist))) ;;text line width assoc 41 for mtext 'box' width (setq newwidth (LM:roundup newwidth MWidth) ) ;;newwidth nearest snap distance (setq newheight (cdr (assoc 40 entlist))) ;;text line width assoc 41 for mtext 'box' width (setq newheight (LM:roundup newheight MHeight) ) ;;newwidth nearest snap distance (setq snap (getreal (strcat "\nEnter MText width (" (rtos newwidth) "): " ) )) (if (= snap nil)(setq snap newwidth)) (setq newwidth snap) (setq snap (getreal (strcat "\nEnter MText Height (" (rtos newheight) "): " ) )) (if (= snap nil)(setq snap newheight)) (setq newheight snap) (setq entlist (subst (cons 40 newheight)(assoc 40 entlist) entlist)) ;;Height (setq elist (subst (cons 41 newwidth)(assoc 41 entlist) entlist)) ;;if txt this is width factor, mtext its text width (entmod elist) (setq ECount (1+ Ecount)) ) ; end repeat (command "undo" "e") (princ) ) Forgot to say... a bit quicker than using properties box, can select all text and just 'enter' through the height / width selection and it will set it to the nearest multiple. Can take out the text height question from the loop, put it earlier in the routine or set it to a value if all texts in the drawing are to be the same size or are all nearly as required Edited February 27, 2023 by Steven P Quote
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.