Author Topic: Is there a tool to compact Mtext boxes? - SOLVED!  (Read 25776 times)

0 Members and 1 Guest are viewing this topic.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Is there a tool to compact Mtext boxes?
« Reply #15 on: June 22, 2011, 10:54:43 AM »
If you use carriage returns instead of the autowrapper (based on MText width), you could just set the width to zero.
And that my friend would get you a lotto of grief in my office.  That was one reason a user was fired for that.

But hey that is just how we roll with out limited, word of mouth, subject to change with the wind, cad standards.  :roll:
Ouch. I just don't see the benefit of an MText width. Then again, most of my non c3d labels are single lines of MText - only using MText over DText because I can use a background mask when needed. Nothing irritates me more than turning on a background mask for a piece of text (especially a road name) and suddenly half my drawing is blacked out because some retard decided to create the MText with a gigantic width.
that user had other issues more serious than cad standards.  But not following cad standards was one of the items on the list.  Your example is good one why we can and need to be different in our cad standards.
That's a different situation. If I was told I had to have a width because of standards, I might argue the 'point', but in the end I'd obviously comply...unless you saw things my way. Mostly it just irritates the hell out of me when people use the width and are incredibly sloppy about it.

I have always utilized a width factor and find it quite irritating that many drawings I receive have no mtext width. The issue is that when creating presentation drawings, the text must be formatted in such a way that allows for width adjustments when there are multiple lines of text. Sometimes a hard carriage return is desired and we have used that.

Ask yourself why every good text editor uses line wrapping, then ask yourself why wouldn't you utilize that in a drawing too.

Incidently, one of the major items I would love to have in mtext formatting would be fit justification for a paragraph.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Is there a tool to compact Mtext boxes?
« Reply #16 on: June 22, 2011, 10:57:26 AM »
If you use carriage returns instead of the autowrapper (based on MText width), you could just set the width to zero.
And that my friend would get you a lotto of grief in my office.  That was one reason a user was fired for that.

But hey that is just how we roll with out limited, word of mouth, subject to change with the wind, cad standards.  :roll:
Ouch. I just don't see the benefit of an MText width. Then again, most of my non c3d labels are single lines of MText - only using MText over DText because I can use a background mask when needed. Nothing irritates me more than turning on a background mask for a piece of text (especially a road name) and suddenly half my drawing is blacked out because some retard decided to create the MText with a gigantic width.
that user had other issues more serious than cad standards.  But not following cad standards was one of the items on the list.  Your example is good one why we can and need to be different in our cad standards.
That's a different situation. If I was told I had to have a width because of standards, I might argue the 'point', but in the end I'd obviously comply...unless you saw things my way. Mostly it just irritates the hell out of me when people use the width and are incredibly sloppy about it.

I have always utilized a width factor and find it quite irritating that many drawings I receive have no mtext width. The issue is that when creating presentation drawings, the text must be formatted in such a way that allows for width adjustments when there are multiple lines of text. Sometimes a hard carriage return is desired and we have used that.

Ask yourself why every good text editor uses line wrapping, then ask yourself why wouldn't you utilize that in a drawing too.

Incidently, one of the major items I would love to have in mtext formatting would be fit justification for a paragraph.
In most situations, I'm not labeling with a long not, it's a couple/one short line of text that I want broken up with carriage returns. Hence the reason I use a zero width to solve any text width issues. Sure, if I'm typing some note, you can guarantee I'll use a wordwrap. I guess I didn't make myself clear enough; sorry about that.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Is there a tool to compact Mtext boxes?
« Reply #17 on: June 22, 2011, 02:28:16 PM »
I thought something like this, but upon testing, I can't seem to get it to work  :-(

Code: [Select]
(defun c:test ( / ss i e )
  (if (setq ss (ssget "_:L" '((0 . "MTEXT"))))
    (repeat (setq i (sslength ss))
      (setq e (entget (ssname ss (setq i (1- i)))))
      (entmod (subst (cons 41 (cdr (assoc 42 e))) (assoc 41 e) e))
    )
  )
  (princ)
)

Works here Lee  :?

Just tried again and still can't get it working (ACAD2010 Student) - attached is a quick screen grab.


alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Is there a tool to compact Mtext boxes?
« Reply #18 on: June 22, 2011, 02:30:01 PM »
I thought something like this, but upon testing, I can't seem to get it to work  :-(

Code: [Select]
(defun c:test ( / ss i e )
  (if (setq ss (ssget "_:L" '((0 . "MTEXT"))))
    (repeat (setq i (sslength ss))
      (setq e (entget (ssname ss (setq i (1- i)))))
      (entmod (subst (cons 41 (cdr (assoc 42 e))) (assoc 41 e) e))
    )
  )
  (princ)
)

Works here Lee  :?

Just tried again and still can't get it working (ACAD2010 Student) - attached is a quick screen grab.


Is the text annotative? Not that it would/could change things, but you never know.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Is there a tool to compact Mtext boxes?
« Reply #19 on: June 22, 2011, 02:38:01 PM »
I thought something like this, but upon testing, I can't seem to get it to work  :-(

Code: [Select]
(defun c:test ( / ss i e )
  (if (setq ss (ssget "_:L" '((0 . "MTEXT"))))
    (repeat (setq i (sslength ss))
      (setq e (entget (ssname ss (setq i (1- i)))))
      (entmod (subst (cons 41 (cdr (assoc 42 e))) (assoc 41 e) e))
    )
  )
  (princ)
)

Works here Lee  :?

Just tried again and still can't get it working (ACAD2010 Student) - attached is a quick screen grab.


Is the text annotative? Not that it would/could change things, but you never know.

No, not annotative.  :|

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Is there a tool to compact Mtext boxes?
« Reply #20 on: June 22, 2011, 02:45:17 PM »
I thought something like this, but upon testing, I can't seem to get it to work  :-(

Code: [Select]
(defun c:test ( / ss i e )
  (if (setq ss (ssget "_:L" '((0 . "MTEXT"))))
    (repeat (setq i (sslength ss))
      (setq e (entget (ssname ss (setq i (1- i)))))
      (entmod (subst (cons 41 (cdr (assoc 42 e))) (assoc 41 e) e))
    )
  )
  (princ)
)

Works here Lee  :?

Just tried again and still can't get it working (ACAD2010 Student) - attached is a quick screen grab.


Is the text annotative? Not that it would/could change things, but you never know.

No, not annotative.  :|
Odd. You code worked for me with annotative text in 2011, but only on the width, not the height and ron's code didn't do anything.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Is there a tool to compact Mtext boxes?
« Reply #21 on: June 22, 2011, 02:49:44 PM »
I thought something like this, but upon testing, I can't seem to get it to work  :-(

Code: [Select]
(defun c:test ( / ss i e )
  (if (setq ss (ssget "_:L" '((0 . "MTEXT"))))
    (repeat (setq i (sslength ss))
      (setq e (entget (ssname ss (setq i (1- i)))))
      (entmod (subst (cons 41 (cdr (assoc 42 e))) (assoc 41 e) e))
    )
  )
  (princ)
)

Works here Lee  :?

Just tried again and still can't get it working (ACAD2010 Student) - attached is a quick screen grab.


Is the text annotative? Not that it would/could change things, but you never know.

No, not annotative.  :|
Odd. You code worked for me with annotative text in 2011, but only on the width, not the height and ron's code didn't do anything.

Yeah, I've only set it to update the Width at this point (stopped when I couldn't even get that working...). (vla-put-width <MText>) doesn't work either for me. Also, the 'Defined Width' property in the Properties Panel for the object is greyed out (uneditable) - is this normal?

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Is there a tool to compact Mtext boxes?
« Reply #22 on: June 22, 2011, 02:51:37 PM »
Yeah, I've only set it to update the Width at this point (stopped when I couldn't even get that working...). (vla-put-width <MText>) doesn't work either for me. Also, the 'Defined Width' property in the Properties Panel for the object is greyed out (uneditable) - is this normal?
WTF, that's really odd. Out of curiosity, does the width program I posted earlier work for you?
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Is there a tool to compact Mtext boxes?
« Reply #23 on: June 22, 2011, 02:59:57 PM »
I thought something like this, but upon testing, I can't seem to get it to work  :-(

Code: [Select]
(defun c:test ( / ss i e )
  (if (setq ss (ssget "_:L" '((0 . "MTEXT"))))
    (repeat (setq i (sslength ss))
      (setq e (entget (ssname ss (setq i (1- i)))))
      (entmod (subst (cons 41 (cdr (assoc 42 e))) (assoc 41 e) e))
    )
  )
  (princ)
)

Works here Lee  :?

Just tried again and still can't get it working (ACAD2010 Student) - attached is a quick screen grab.


Is the text annotative? Not that it would/could change things, but you never know.

No, not annotative.  :|
Odd. You code worked for me with annotative text in 2011, but only on the width, not the height and ron's code didn't do anything.

This didn't work for you Alan? Try it again ... I reposted because I forgot to set the elist to "e" in the first entmod.

http://www.theswamp.org/index.php?topic=38691.msg437960#msg437960

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Is there a tool to compact Mtext boxes?
« Reply #24 on: June 22, 2011, 03:02:44 PM »
I thought something like this, but upon testing, I can't seem to get it to work  :-(

Code: [Select]
(defun c:test ( / ss i e )
  (if (setq ss (ssget "_:L" '((0 . "MTEXT"))))
    (repeat (setq i (sslength ss))
      (setq e (entget (ssname ss (setq i (1- i)))))
      (entmod (subst (cons 41 (cdr (assoc 42 e))) (assoc 41 e) e))
    )
  )
  (princ)
)

Works here Lee  :?

Just tried again and still can't get it working (ACAD2010 Student) - attached is a quick screen grab.


Is the text annotative? Not that it would/could change things, but you never know.

No, not annotative.  :|
Odd. You code worked for me with annotative text in 2011, but only on the width, not the height and ron's code didn't do anything.

This didn't work for you Alan? Try it again ... I reposted because I forgot to set the elist to "e" in the first entmod.

http://www.theswamp.org/index.php?topic=38691.msg437960#msg437960
Cool, that worked. I doubt I'll ever use it, but It's going in the toolbox. :)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Is there a tool to compact Mtext boxes?
« Reply #25 on: June 22, 2011, 03:04:51 PM »
Yeah, I've only set it to update the Width at this point (stopped when I couldn't even get that working...). (vla-put-width <MText>) doesn't work either for me. Also, the 'Defined Width' property in the Properties Panel for the object is greyed out (uneditable) - is this normal?
WTF, that's really odd. Out of curiosity, does the width program I posted earlier work for you?

Nope. I added a vl-catch-all-error-p/message to check it if the vl-catch-all-apply threw an error, but no error, it just doesn't do anything.


alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Is there a tool to compact Mtext boxes?
« Reply #26 on: June 22, 2011, 03:08:27 PM »
Yeah, I've only set it to update the Width at this point (stopped when I couldn't even get that working...). (vla-put-width <MText>) doesn't work either for me. Also, the 'Defined Width' property in the Properties Panel for the object is greyed out (uneditable) - is this normal?
WTF, that's really odd. Out of curiosity, does the width program I posted earlier work for you?

Nope. I added a vl-catch-all-error-p/message to check it if the vl-catch-all-apply threw an error, but no error, it just doesn't do anything.


How odd. We jumped from 9 to 11, so I can't even venture an opinion about 2010 issues. Speaking of, since you don't have to pay for it, why not upgrade, or do they allow for that? Work allows for me to have a full-blown copy at home, so I haven't experimented.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Is there a tool to compact Mtext boxes?
« Reply #27 on: June 22, 2011, 03:14:42 PM »
Yeah, I've only set it to update the Width at this point (stopped when I couldn't even get that working...). (vla-put-width <MText>) doesn't work either for me. Also, the 'Defined Width' property in the Properties Panel for the object is greyed out (uneditable) - is this normal?
WTF, that's really odd. Out of curiosity, does the width program I posted earlier work for you?

Nope. I added a vl-catch-all-error-p/message to check it if the vl-catch-all-apply threw an error, but no error, it just doesn't do anything.

How odd. We jumped from 9 to 11, so I can't even venture an opinion about 2010 issues. Speaking of, since you don't have to pay for it, why not upgrade, or do they allow for that? Work allows for me to have a full-blown copy at home, so I haven't experimented.

They do offer a student upgrade to '11 but I was happy with 2010 so never chose/couldn't be bothered to upgrade  :-)
« Last Edit: June 22, 2011, 03:18:43 PM by Lee Mac »

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Is there a tool to compact Mtext boxes?
« Reply #28 on: June 22, 2011, 03:22:51 PM »
Yeah, I've only set it to update the Width at this point (stopped when I couldn't even get that working...). (vla-put-width <MText>) doesn't work either for me. Also, the 'Defined Width' property in the Properties Panel for the object is greyed out (uneditable) - is this normal?
WTF, that's really odd. Out of curiosity, does the width program I posted earlier work for you?

Nope. I added a vl-catch-all-error-p/message to check it if the vl-catch-all-apply threw an error, but no error, it just doesn't do anything.

How odd. We jumped from 9 to 11, so I can't even venture an opinion about 2010 issues. Speaking of, since you don't have to pay for it, why not upgrade, or do they allow for that? Work allows for me to have a full-blown copy at home, so I haven't experimented.

They do offer a student upgrade to '11 but I was happy with 2010 so never chose/couldn't be bothered to upgrade  :-)
Right on. Just curious.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

VVA

  • Newt
  • Posts: 166
Re: Is there a tool to compact Mtext boxes?
« Reply #29 on: June 22, 2011, 03:23:33 PM »
My wariant
Code: [Select]
(defun mip-mtext-wrap-BB (en / el SetHandles CheckHandles sclst)
;;; Argument: the ename of an mtext
;;; Shrinkwrap the bounding box of selected MText objects
;;; http://discussion.autodesk.com/forums/message.jspa?messageID=5734567
;;; ShrinkwrapMText v2a.lsp - Joe Burke - 10/13/2007 - Version 2a
;;;;;http://discussion.autodesk.com/forums/thread.jspa?threadID=448625
;;;; USE:  
;;; (mip-mtext-wrap-BB (car(entsel)))
  
;;; !!!! AutoCAD 2010 2011 2012
;;; http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/MTEXT-Column-property/m-p/2690952
;;;Need to change the column type from dynamic to not add the dxf group of 75 with 0
;;; http://www.theswamp.org/index.php?topic=28243.0
;|
(defun C:TEST ()
  (and
    (setq mtext (car(entsel "\nSelect Mtext to change columns type: ")))
    (setq lst (entget mtext))
    (= (cdr(assoc 0 lst)) "MTEXT")
    (setq lst (if (assoc 75 lst)                        
     (subst (cons 75 0) (assoc 75 0) lst)
     (append lst (list(cons 75 0)))
     )
 )
    (entmod lst)
    )
  (princ)
  )
|;
  

  (defun GetAnnoScales (e / dict lst rewind res)
;;; Argument: the ename of an annotative object.
;;; Returns the annotative scales associated with the
;;; ename as a list of strings.
;;; Example: ("1:1" "1:16" "1:20" "1:30")
;;; Returns nil if the ename is not annotative.
;;; Can be used to test whether ename is annotative or not.
;;; Works with annotative objects: text, mtext, leader, mleader,
;;; dimension, block reference, tolerance and attribute.
;;; Based on code by Ian Bryant.

    (if
      (and
        e
        (setq dict (cdr (assoc 360 (entget e))))
        (setq lst (dictsearch dict "AcDbContextDataManager"))
        (setq lst
               (dictsearch (cdr (assoc -1 lst)) "ACDB_ANNOTATIONSCALES")
        ) ;_ end of setq
        (setq dict (cdr (assoc -1 lst)))
      ) ;_ end of and
       (progn
         (setq rewind t)
         (while (setq lst (dictnext dict rewind))
           (setq e      (cdr (assoc 340 lst))
                 res    (cons (cdr (assoc 300 (entget e))) res)
                 rewind nil
           ) ;_ end of setq
         ) ;_ end of while
       ) ;_ end of progn
    ) ;_ end of if
    (reverse res)
  )                                               ;end


  (defun CheckHandles (e / dict lst rewind nlst d42 d43 n p ptlst)
;;; Argument: the ename of annotative mtext object.
;;; Returns T if the object has only one scale or
;;; the handles for all scales are proportionally the
;;; same and all scales use the same insertion point.
    (if
      (and
        e
        (setq dict (cdr (assoc 360 (entget e))))
        (setq lst (dictsearch dict "AcDbContextDataManager"))
        (setq lst
               (dictsearch (cdr (assoc -1 lst)) "ACDB_ANNOTATIONSCALES")
        ) ;_ end of setq
        (setq dict (cdr (assoc -1 lst)))
      ) ;_ end of and
       (progn
         (setq rewind t)
         (while (setq lst (dictnext dict rewind))
           (setq nlst   (cons lst nlst)
                 rewind nil
           ) ;_ end of setq
         ) ;_ end of while
         (cond
           ((= 1 (length nlst)))
           (t
            ;; lst is nil so reuse it.
            (foreach x nlst
                                                  ;Horizontal width. Can be zero, a null text string.
              (setq d42   (cdr (assoc 42 x))
                                                  ;Vertical height cannot be zero so a divide
                                                  ;by zero error can't happen.
                    d43   (cdr (assoc 43 x))
                    n     (/ d42 d43)
                    lst   (cons n lst)
                                                  ;Insertion point
                    p     (cdr (assoc 11 x))
                    ptlst (cons p ptlst)
              ) ;_ end of setq
            ) ;_ end of foreach
            (and
              (vl-every '(lambda (x) (equal n x 1e-4)) lst)
              (vl-every '(lambda (x) (equal p x 1e-4)) ptlst)
            ) ;_ end of and
           )
         ) ;_ end of cond
       ) ;_ end of progn
    ) ;_ end of if
  )                                               ;end

  (defun SetHandles (lst / oldlst charwidth ht pat)
;;;    ;Argument: an entget list.
;;;    ;Code 42 is the smallest width of the handles.
;;;    ;If 41 is larger than 42 then the handles can be shrunk  
;;;    ;horizontally given a single line mtext object.
;;;
;;;    ;Code 46 is the current height of the handles in 2007/2008.
;;;    ;Substitute the actual height from the code 43 value.
;;;
;;;    ;Used to determine number of objects modified.
  (setq lst (entget (cdr(assoc -1 lst)) '("ACAD")))
;;;    (setq oldlst lst)
    (setq charwidth (* (cdr (assoc 42 lst)) 1.05) ;_1.035
          ht        (cdr (assoc 43 lst))
          lst       (subst (cons 41 charwidth) (assoc 41 lst) lst)
          lst       (subst (cons 46 ht) (assoc 46 lst) lst)
 lst       (if (assoc 75 lst)                          ;;; 75 - òèï êîëîíîê
     (subst (cons 75 0) (assoc 75 0) lst)
     (append lst (list(cons 75 0)))
     )
    ) ;_ end of setq
;;;Code 46 is the current height of the handles in 2007/2008.
;;;Substitute the actual height from the code 43 value.
  
    (if (and
          (setq pat (assoc -3 lst))
          (eq "ACAD" (caadr pat))
        ) ;_ end of and
      (progn
      (if (assoc 46 lst)
;;;Code 46 is the current height of the handles in 2007/2008.
;;; Remove extended data regarding height if found.
        (setq pat '(-3 ("ACAD")))
        (progn
          (setq pat
                 (cons -3
                       (list (subst (cons 1040 ht)
                                    (assoc 1040 (cdadr pat))
                                    (cadr pat)
                             ) ;_ end of subst
                       ) ;_ end of list
                 ) ;_ end of cons
          ) ;_ end of setq
        ) ;_ end of progn
      ) ;_ end of if
      (setq lst (subst pat (assoc -3 lst) lst))
      )
    ) ;_ end of if
    (setq lst (entmod lst))
  )                                               ;end SetHandles

  (if (= (cdr (assoc 0 (setq EL (entget en '("*"))))) "MTEXT")
    (progn
      (cond
        ((and
           (setq sclst (GetAnnoScales en))
           (CheckHandles en)
         ) ;_ end of and
         (vl-cmdf "._chprop" en "" "_Annotative" "_No" "")
                                                  ;(SetHandles (entget ename))
         (SetHandles el)
         (vl-cmdf "._chprop" en "" "_Annotative" "_Yes" "")
         (foreach x sclst
           (vl-cmdf "._objectscale" en "" "_Add" x "")
         ) ;_ end of foreach
        )
        ((not (GetAnnoScales en))
         (SetHandles el)
        )
        (t nil)
      ) ;_ end of cond
    ) ;_ end of progn
  ) ;_ end of if
) ;_ end of defun
Use
Code: [Select]
(defun C:TEST (/ ss i)
  (and (setq ss (ssget "_:L" '((0 . "MTEXT"))))
       (repeat (setq i (sslength ss))
(mip-mtext-wrap-BB (ssname ss (setq i (1- i))))
       )
       (setq ss nil)
  )
)