Ajust Mtext width

Ajust Mtext width

C.Utzinger
Collaborator Collaborator
1,493 Views
4 Replies
Message 1 of 5

Ajust Mtext width

C.Utzinger
Collaborator
Collaborator

HI

I found a lot of routines to Change the Mtext width to 0, but I'm looking for one that just ajust the width like in the DWG example attached.

 

The Routine im using for the Moment:

(defun c:<test1 (/ ss acDoc i e)

  (if (setq ss (ssget "_:L" '((0 . "MTEXT"))))    
      (repeat (setq i (sslength ss))
        (setq e (entget (ssname ss (setq i (1- i))))
              e (append e '((75 . 0)))
              e (subst '(41 . 0.0) (assoc 41 e) e)
        )
        (entmod e)
      )
  )
)

 

Thanks for help

0 Likes
Accepted solutions (1)
1,494 Views
4 Replies
Replies (4)
Message 2 of 5

_gile
Consultant
Consultant

Hi,

 

Try something like this:

(defun c:test1 (/ w ss i e)
  (if
    (and (setq w (getdist "\nText width: "))
         (setq ss (ssget "_:L" '((0 . "MTEXT"))))
    )
     (repeat (setq i (sslength ss))
       (setq e (entget (ssname ss (setq i (1- i)))))
       (entmod (subst (cons 41 w) (assoc 41 e) e))
     )
  )
  (princ)
)

You can also use setpropertyvalue instead of entmod.

(defun c:test2 (/ w ss i e)
  (if
    (and (setq w (getdist "\nText width: "))
         (setq ss (ssget "_:L" '((0 . "MTEXT"))))
    )
     (repeat (setq i (sslength ss))
       (setq e (ssname ss (setq i (1- i))))
       (setpropertyvalue e "Width" w)
     )
  )
  (princ)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 5

C.Utzinger
Collaborator
Collaborator
Accepted solution

HI

 

I just found what I was looking for.

 

Thank you anyway

 

(defun mip-mtext-wrap-BB (en / el SetHandles CheckHandles sclst)
 
(defun GetAnnoScales (e / dict lst rewind res)
 
 (if (and e 
          (setq dict (cdr (assoc 360 (entget e))))
          (setq lst (dictsearch dict "AcDbContextDataManager"))
          (setq lst (dictsearch (cdr (assoc -1 lst)) "ACDB_ANNOTATIONSCALES"))
          (setq dict (cdr (assoc -1 lst)))
     )
     (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
         ) 
       ) 
     )
 )
 (reverse res)
)
 
(defun CheckHandles (e / dict lst rewind nlst d42 d43 n p ptlst)
 
 (if (and e
          (setq dict (cdr (assoc 360 (entget e))))
          (setq lst (dictsearch dict "AcDbContextDataManager"))
          (setq lst (dictsearch (cdr (assoc -1 lst)) "ACDB_ANNOTATIONSCALES"))
          (setq dict (cdr (assoc -1 lst)))
     )
     (progn
       (setq rewind t)
       (while (setq lst (dictnext dict rewind))
         (setq nlst (cons lst nlst)
               rewind nil
         ) 
       )
       (cond ((= 1 (length nlst)))
             (t (foreach x nlst 
                   (setq d42 (cdr (assoc 42 x)) 
                         d43 (cdr (assoc 43 x))
                         n (/ d42 d43)
                         lst (cons n lst)
                         p (cdr (assoc 11 x))
                         ptlst (cons p ptlst))
                )
                (and
                  (vl-every '(lambda (x) (equal n x 1e-4)) lst)
                  (vl-every '(lambda (x) (equal p x 1e-4)) ptlst)
                )
             ) 
       )
     )
 )
)
 
(defun SetHandles (lst / oldlst charwidth ht pat)
 
  (setq lst (entget (cdr(assoc -1 lst)) '("ACAD")))
  (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)
                (subst (cons 75 0) (assoc 75 0) lst)
                (append lst (list(cons 75 0)))
            )
  )
  
 (if (and
       (setq pat (assoc -3 lst))
       (eq "ACAD" (caadr pat))
     )
     (progn
       (if (assoc 46 lst)
           (setq pat '(-3 ("ACAD")))
           (setq pat (cons -3 (list (subst (cons 1040 ht) (assoc 1040 (cdadr pat)) (cadr pat))))) 
       )
       (setq lst (subst pat (assoc -3 lst) lst))
     )
 )
 
 (setq lst (entmod lst))
 
)
 

(if (= (cdr (assoc 0 (setq EL (entget en '("*"))))) "MTEXT") 
    (cond ((and (setq sclst (GetAnnoScales en)) (CheckHandles en))
           (vl-cmdf "._chprop" en "" "_Annotative" "_No" "") 
           (SetHandles el)
           (vl-cmdf "._chprop" en "" "_Annotative" "_Yes" "")
           (foreach x sclst
             (vl-cmdf "._objectscale" en "" "_Add" x "")
           )
          )
          ((not (GetAnnoScales en))
           (SetHandles el)
          )
          (t nil)
    ) 
)
 
)
 
(defun C:<Test1 (/ 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)
  )

)
0 Likes
Message 4 of 5

ВeekeeCZ
Consultant
Consultant

It would be nice of you if you reveal the source and noted the author(s). 

The origin source is probably HERE at theswamp.org

Nice find though.

 

0 Likes
Message 5 of 5

C.Utzinger
Collaborator
Collaborator

HI

Yes you're  right.

 

I found it here:

 

https://autocadtips1.com/2011/08/13/autolisp-text-box-width/

 

Note: I cleaned it and eliminated some "progn"

 

Kind regards

0 Likes