Shrink Wrap multileader and mtext help

Shrink Wrap multileader and mtext help

tclappER5PH
Participant Participant
354 Views
3 Replies
Message 1 of 4

Shrink Wrap multileader and mtext help

tclappER5PH
Participant
Participant

I used to have an autolisp routine that would emulate the double-click on the double arrows within the WYSIWYG text editor box. It would NOT zero out the text width. Just shrink wrap the text mask to fit the text box. I somehow lost it and cannot find it online anywhere. Everything I have found just zeros the text width.

 

Does anyone know or have a routine that would do this?

 

 

 Screenshot 2025-03-19 133705.png

0 Likes
355 Views
3 Replies
Replies (3)
Message 2 of 4

LDShaw
Collaborator
Collaborator

Try this one. 

;;; ==============================================================================
;;; Lisp Name: width height text change.lsp
;;; Author: unknown
;;; Date Created: 2023/05/12
;;; Last Edited: [Insert Last Edit Date]
;;;
;;; DESCRIPTION:
;;; Adjusts the width and height of MTEXT entities in AutoCAD.
;;;
;;; Usage:
;;; 1. Load the Lisp routine.
;;; 2. Run the command "textchanges" in AutoCAD.
;;;
;;; Parameters:
;;; None
;;;
;;; Returns:
;;; None
;;;
;;; Notes:
;;;
;;;
;;; ---------------------------- Main program --------------------------------;

;; Define a function called mip-mtext-wrap-BB that takes 'en' as an argument.
(defun mip-mtext-wrap-BB (en / el SetHandles CheckHandles sclst)

  ;; Define a function called GetAnnoScales that takes 'e' as an argument.
  (defun GetAnnoScales (e / dict lst rewind res)

    ;; Check if 'e' exists and retrieve annotation scales from the entity's dictionary.
    (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
        ;; Initialize variables for processing annotation scales.
        (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) ; Return a list of annotation scales.
  )

  ;; Define a function called CheckHandles that takes 'e' as an argument.
  (defun CheckHandles (e / dict lst rewind nlst d42 d43 n p ptlst)

    ;; Check if 'e' exists and retrieve annotation scales from the entity's dictionary.
    (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
        ;; Initialize variables for processing annotation scales.
        (setq rewind t)
        (while (setq lst (dictnext dict rewind))
          (setq nlst (cons lst nlst)
                rewind nil)
          )
        ;; Check if annotation scales are consistent.
        (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)
                 )
              )
        )
      )
    )
  )

  ;; Define a function called SetHandles that takes 'lst' as an argument.
  (defun SetHandles (lst / oldlst charwidth ht pat)

    ;; Extract necessary properties from 'lst'.
    (setq lst (entget (cdr (assoc -1 lst)) '("ACAD")))
    (setq charwidth (* (cdr (assoc 42 lst)) 1.25) ; Adjust character width.
          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)))
              )
    )

    ;; Check and update the annotation scale.
    (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))
       )
    )

    ;; Update the entity with modified properties.
    (setq lst (entmod lst))

  )

  ;; Check if the entity is MTEXT.
  (if (= (cdr (assoc 0 (setq EL (entget en '("*"))))) "MTEXT")
      (cond ((and (setq sclst (GetAnnoScales en)) (CheckHandles en))
             ;; If annotation scales exist and handles are consistent, perform the following actions:
             (vl-cmdf "._chprop" en "" "_Annotative" "_No" "") ; Set entity as non-annotative.
             (SetHandles el) ; Set handles for the entity.
             (vl-cmdf "._chprop" en "" "_Annotative" "_Yes" "") ; Set entity as annotative.
             (foreach x sclst
               (vl-cmdf "._objectscale" en "" "_Add" x "") ; Add annotation scales.
             )
            )
            ((not (GetAnnoScales en))
             ;; If no annotation scales exist, set handles for the entity.
             (SetHandles el)
            )
            (t nil)
      )
  )
)

;; Define a command called C:<Test1 that takes no arguments.
(defun C:textchanges (/ ss i)

  ;; Check if there are MTEXT entities in the drawing.
  (and (setq ss (ssget "_:L" '((0 . "MTEXT"))))
       (repeat (setq i (sslength ss))
               (mip-mtext-wrap-BB (ssname ss (setq i (1- i)))) ; Process each MTEXT entity.
       )
       (setq ss nil)
  )

)
0 Likes
Message 3 of 4

tclappER5PH
Participant
Participant

unfortunately it's not working. comes back with "nil."
plus, the one i had worked with MTEXT and MLEADER TEXT. This is just for MTEXT.

 

But thank you for the response.

0 Likes
Message 4 of 4

gbattinPH5TG
Advocate
Advocate

Sorry - edited because it only works on Mtext

0 Likes